Forum Moderators: coopster
I'm using a fancy JavaScript/Flash uploading tool, which POSTS a file upload to a back-end PHP script. I had it all working great, for small JPGs and GIFs and PNGs. But then I tested it using a large JPG from my digital camera... and it failed.
The Flash uploader enforces a file size max of 3MB. The largest photos taken from my camera are around 2.7MB, so this is a sensible limit which allows some high-rez photos, but will turn away someone trying to upload enormous garbage.
After oodles of tracing and troubleshooting and research, I discovered that some of my default PHP settings were too low. In particular:
memory_limit - this needs to be very large because I'm uncompressing a JPG to its native bitmap format in memory to create thumbnails using PHP's GD library. I set this to "140M"
max_execution_time - also needed to be augmented. I set this to "1200"
upload_max_filesize - limited the size of the file that could be uploaded. Of course the default was too small. I changed this to "80M"
post_max_size - same as above. The FILE shows up in a POST, so naturally POST has to be big enough to hold the FILE.
max_input_time - not obvious at first, but apparently this also needed to be increased. I set this to "1200"
I tried to change all these settings only on the current page, by adding these lines to the very top of my script:
ini_set("memory_limit","140M");
ini_set("max_execution_time","1200");
ini_set("upload_max_filesize","80M");
ini_set("post_max_size","80M");
ini_set("max_input_time","1200");
Still, large images were causing a 500 Server Error.
I discovered the issue by adding a php_info() after these, and saw that the first two - memory_limit and max_execution_time - were changed. But the last three - upload_max_filesize, post_max_size, and max_input_time, were unchanged!
The epiphany came when I realized that by the time a PHP script on a page is executed, the POST has already happened. So it's meaningless to change those settings on the page! They need to be changed in the php.ini, .htaccess or httpd.conf.
This old post (by coopster) was the key to my enlightenment:
[webmasterworld.com...]
I added these lines to my .htaccess file:
php_value upload_max_filesize "80M"
php_value post_max_size "80M"
php_value max_input_time "1200"
And now I can upload really huge JPGs taken with my 10.2 megapixel digital camera.
Eureka!
Now I'd like to tidy up, by:
1) adding a condition to my .htaccess so those settings are only increased on the page where the upload form exists. On all the other pages of my site, the regular default values are more than sufficient. I'm not so fluent with .htaccess so perhaps someone can guide me there? Do I use a RewriteCond?
2) nudge the settings down until they're as large as they need to be but not so extreme. I may have overshot the memory_limit etc in my exasperated attempts at debugging this problem.
...I set this to "140M"
Setting resource usage this high made me very uncomfortable . . . if at all possible, you should really look at ImageMagick/Imajick. All this goes away because 1) ImageMajick is launched as a separate process, and 2) it doesn't suck up your memory.
Option Two for large uploads [webmasterworld.com]