Archives » June 27th, 2006

June 27, 2006


2006-06-26 024

Getting Around PHP Upload Limits

I ran into a problem on my sister site this morning, that had to do with file uploads. I’m using PHP to allow people to upload photos to the site, and there’s a form with an <input type="file"> text field that they use to pick the picture to be uploaded. I’ve never had a problem with this form, but someone this morning tried to upload a picture and got all kinds of nasty PHP errors. What could be the problem?

Well I found a setting buried deep in PHP, post_max_size, a directive that tells PHP what the largest amount of POST data it should accept is. Normally this is set to a default of 8 Megabytes, but my host had changed it to 2MB. (But oddly enough they left the more precise directive, upload_max_filesize, at the default of 8MB.)

All I had to do to override their setting was add a line to my .htaccess file:
php_value post_max_size 8M

That put the setting back to 8MB, and the photo was able to be uploaded with no problem. Now I won’t have any more problems until digital cameras start producing files over 8MB. Or until someone decides to upload a RAW image!