Uploading Large Files With PHP
Let me first start by saying that I’m currently working at a startup, and for anyone who’s ever done this, you know it sucks up a LOT of your time… in my case pretty much all of it. I’m not complaining by any means, I’m doing some of the coolest work I’ve ever done in fact! However, I just wanted to explain my little posting hiatus…
Anyway, on to the matter at hand. I have found myself in a position where I am writing scripts that may need to upload fairly large files. My scripts were timing out, and I couldn’t seem to figure out why. For the unitiated, there are some standard things that you usually do to both your php.ini and in your script in this situation:
- Set your max_upload_size in php.ini higher (it’s only 2M out of the box)
- Set your script timeout to never (set_time_limit(0); in your scripts… don’t do this in your php.ini)
However, it turns out there are some other php.ini config variables that you may need to look at:
- memory_limit – This may also be an obvious one to some people, but for those of you who don’t know, this restricts how much memory PHP is allowed to consume while processing. When working with images and large files, this needs to be upped to accommodate these needs.
- post_max_size – This was the one killing me, and it was a major “Duh” moment as well. If you aren’t allowed to create a large post, how can you expect to upload a large file?? This should be set the same as your max_upload_size.
- max_input_time – the time that the script should spend in accepting input. This is setting defaults to 60 seconds, and you will probably need to update this as well
That’s about it! Quick and simple solution to a problem that is probably pretty common.













