PHP: upload_max_filesize

Tue 17 Apr

2007

I ran into this problem today, so I thought I would share, in case anyone else experiences the same issue…

I had a page that accepted an image upload via a form. I tested it pretty thoroughly and thought I had everything working, so I sent the link to a co-worker to have him give it a try. (If there’s something wrong, this guy will manage to find it… and he did.)

For some reason, when he tried to submit the form, all of the other information would write to the database as it should, but the image wasn’t being uploaded. I sat there baffled for a second, thinking it was that he was trying to upload a .jpg and I had tested with a .gif, but that wasn’t it because I had tested with several .jpgs. I had the form tag’s enctype attribute set correctly to ‘multipart/form-data’, but for some reason, when he tried it, it didn’t work.

Turns out it was the ‘upload_max_filesize‘ in the php.ini. I had it set at the default value of 2M (2 megabytes) and the picture he was trying to upload was 2.11MB. So, lesson learned: If you are going to allow uploads, check ‘upload_max_filesize’ in your script using ini_get(). Then compare the value to the file size being uploaded so you can make sure to tell the user when their file is too big.

Also, watch out for ‘post_max_size‘. It should be >= ‘upload_max_filesize’. It is set to 8M by default, so you probably won’t have an issue, but I thought I would mention it just in case. :)

Comments

Leave a Reply