Uploading large files: covering all the bases
When uploading a file to a PHP script on an Apache web server, there are several configuration options that if improperly set can get in the way. I just encountered yet another one of these, and decided to catalog them here.
Size, Time, and Memory
There are three types of limits that affect file uploads, and the weakest link in the chain is your effective limit.
If your size limit is set to 3gb, but your time limit does not allow for the time required to upload that much data, you’ll still be unable to upload those large files. Likewise, the ability to upload does no good if you do not have enough memory to process the file that was uploaded.
Assumptions
This post assumes an 8MB upload limit (8mb x 1024kb x 1024 bytes = 8388608). You will want to adjust this number up or down according to your needs.
Oddly, although 8mb is the default value for PHP’s upload_max_filesize
setting, some of the other default settings are much lower (2mb, or in some cases, only 100k).
PHP limits
upload_max_filesize = 8388608
post_max_size = 8388608
max_input_time = 60
Depending on what you’re doing with the uploaded files, you may also need to increase your memory limit:
memory_limit = 64MB
Apache limits
If LimitRequestBody
is set to something non-zero, you may need to increase its value in your Apache httpd.conf
file or .htaccess
file:
LimitRequestBody 8388608
If you are using mod_fcgid
(required to run the latest PHP 5.3 VC9 NTS build for Windows), then you need to set the value of FcgidMaxRequestLen
, which defaults to 100k if it is not set. (Note that some systems may put mod_fcgid
settings in a file separate from the main httpd.conf
file).
FcgidMaxRequestLen 8388608
FcgidIOTimeout 60
Happy uploading!