It’s a common request on the internet:
How to increase the maximum upload file size for WordPress (or any other blog based on PHP).
There can be several reasons for increasing the maximum upload size, especially when you take into account that the default is usually set to a ridiculously low value of
2MB. I.e., you may want to upload large pictures from your digital camera (high quality jpegs can easily take up 15MB or more nowadays) or you want to upload movies, zipfiles, programs etc. Whatever your reason, here’s how:
How to increase the max upload file size in PHP
The first half of the answer is often cited as the complete answer. And don’t be fooled, just increasing
upload_max_filesize in your
php.ini won’t cut it:
memory_limit = 128M upload_max_filesize = 32M post_max_size = 64M file_uploads = On
But this may not be enough. Depending on your upload link speed and the speed of your server, you may receive maximum execution time exceeded errors, see next little section for a solution.
This is the maximum consumable memory limit by your php application. I’m not sure whether it is per thread or in total. See also original reference.
Compared to the filesize, the memory limit may look rather high. However, quite some php file processing scripts require more memory than just the filesize. I noticed this in particular for WordPress when posting large posts containing many shortcodes.
The actual, literal max files size. It is not the maximum size of binhex encoded octets, it is the size your file would have after decoding took place. See also original reference.
A HTTP POST request is required for any file upload. However, a form often contains more fields or even more file uploads. Hence, this number must be higher than
upload_max_filesize. See also original reference.
upload_max_filesize, because a form often has more elements, plus some forms allow uploading more than one file at once
Switch this to
On to allow file uploads. Without it, none of the previous settings have any effect (well, except the memory setting). See also original reference.
ini_set, i.e. in WordPress you can do so in
wp_settings.php. This approach is not allowed by all hosting providers, simply because they don’t like you tampering with these settings.
Solving maximum execution time exceeded PHP Fatal error
Uploading these files can take a considerable amount of time and PHP is not going to wait indefinitely for your upload to succeed. If it fails because it’s tired of waiting, you’ll find the following error in your Apache or IIS error logs:
[error] [client 184.108.40.206] PHP Fatal error: Maximum execution time of 30 seconds exceeded in [...]
This error is misleading, as you’ll receive the same error when the upload time is exceeded, which isn’t the same as the execution time (the time it takes to process the received file, i.e. for creating thumbnails of large images).
The solution is simple, once you know where to look. Just change the following settings in php.ini, increase them until the time is large enough for both uploading time and processing time of your input:
default_socket_timeout = 300 max_execution_time = 300 max_input_time = 300
All settings are in seconds. A little explanation on the settings:
The socket timeout prevents the open connection you have while uploading, to timeout prior to the file being uploaded completely. If you have relatively low upload bandwidth, which is common with ADSL connections, you probably want this number relatively high. See also original reference.
This is the maximum time the script may take to execute the request. Apparently, this is including the time you start uploading the file. So, this time is the upload time, plus the execution time. Unfortunately, when you have a rogue script, you may only find out after it runs for this long before it is shut down. All that time it may consume all the CPU of one of your processors. See also original reference.
This is the maximum time it takes for a file from start of upload to end of upload. If your script doesn’t need long to execute (i.e., if it simply stores the uploaded file) this number can be equal to
max_execution_time. See also original reference.
It seems there’s an error in the documentation. It states:
It is measured from the moment of receiving all data on the server to the start of script execution.
which isn’t true in practice, at least not for me. A script required less than a second to process the input, but 120 seconds for uploading. Without increasing this value, I couldn’t get uploads working correctly.