Forum Moderators: coopster
I am trying to build a form to upload 5 photos at once.
The logic of my code is as follows:
for ($i=1; $i<=5; $i++) // counter
{
$var = 'picture'.$i;
if $_FILES[$var]... //exists/is jpg/has legal name/ other validations
// check photo dimensions and resize if necessary to max width 700px
// save photo
}
Now the above works normaly when i try to upload 5 images 1024x768 or even bigger (up to 1600)
The script fails when i try to upload my photos from a digital camera (dimensions can be from 2k up to 8k in width and filesize can be from a couple of MB to 10-15MB of jpg)
*Note: yes, there are users that try to upload such files all at once <grins>.
I dont get any message at all, although i have set up numerous error messages - script behaves as though the photo never submitted.
I tried increasing the memory to 8M in the php ini and still nothing.
What can i done to avoid this? OR to get at least a descent message notifying my of the failure?
Thanks for any tip
Maybe your script is just timing out which is why no error at all is received. Also have you tried changing
POST_MAX_SIZE
and
UPLOAD_MAX_FILESIZE
in your php.ini file?
I tried increasing the memory to 8M in the php ini and still nothing.
It's not just the memory, it's also execution time, max upload size . . . for example, from one PHP site .htaccess . . .
php_flag file_uploads on
php_value post_max_size "20M"
php_value upload_max_filesize "10M"
php_value max_input_time "300"
php_value memory_limit "64M"
If you're not resizing the image, check your phpinfo() to make sure it's doing what you tell it to. If it's not, note that you can also do the same thing via .htaccess on a per-directory basis. This is slightly more secure as it limits the large sizes to a directory instead of system wide, or the php.ini updates may not be allowed on your host.
If you use the GD toolkit to manipulate/resize these in any way, you will find a little bit you didn't know and haven't encountered yet.
When you upload an image, the image is normally compressed. When the GD toolkit manipulates this image, it creates an uncompressed bitmap in memory - that is, like a .bmp. What this tends to do with large images is fail due to memory limits assigned to PHP.
So if the image is 8 MB compressed and you attempt to resize it, it can use 100-200 MB of memory to process the image. Not good.
The solution is to use Imagick/ImageMagick as it does this in a completely different way that doesn't hog up your memory and other resources, plus it has a lot of things you can do you can't do with GD.
More info on PHP upload limits [webmasterworld.com]
A little Imagic info [webmasterworld.com]
rocknbil, i didn't knew of the compress/uncompress method of the GD library. And although I've heard of the imagemagick, we never used it before.
I will use the htaccess rules to test how this will go, else.. its time for a little reading and experimet with image magick
Thank you both for the info/insight.