Skip navigation

We are still here! - Following government advice we are now working with most of our staff at home, but otherwise operating as normal. Please see our Contact page for more information on the best way to contact us during this time.

Blog > Upload large files to a website

Recently we had an issue where we needed to upload large document files through the browser. Uploading documents through the browser is normally limited to around 10 to 15MB using a simple HTML form and for most users that is sufficient. When documents are above this size the file upload will usually fail due to the upload timing out.

There are various methods to increase the maximum document size that can be uploaded through the browser but we did not know that htaccess could be used to allow large document uploads. We thought that FTP or Flash would be the only methods for uploading large files.

Then we discovered the following code that can be inserted into a htaccess file to enable much larger file uploads. In this example l have set it to allow for 500MB files:

<code>php_value max_execution_time 3600
php_value upload_max_filesize 500M
php_value post_max_size 500M
php_value memory_limit -1
php_value max_input_time -1
LimitRequestBody 0</code>

Uploading documents of this large size will only be possible through a PC with a fast upload connection due to the maximum execution time being 1 hour.

Below is an explanation of what each of the parts of the htaccess code mean.

<code>php_value max_execution_time 3600</code>

The max_execution_time variable sets the maximum number of seconds PHP will wait for the upload to finish before terminating it.

<code>php_value upload_max_filesize 500M</code>

The upload_max_filesize variable sets the maximum file size the upload can handle. The upload will terminate once this value is exceeded. This is usually set to 2MB by default on the server.

<code>php_value post_max_size 500M</code>

The post_max_size variable sets the maximum file size the upload can handle when the file is sent from a 'multipart/form-data' form. The upload will terminate once this value is exceeded.

<code>php_value memory_limit -1</code>

The memory_limit variable sets the maximum memory size the upload can handle. By setting this to -1 means that the upload can use any memory size and is unlimited.

<code>php_value max_input_time -1</code>

The max_input_time variable is simliar to the max_execution_time variable. It sets the maximum time the script can run for. By setting this to -1 means that the upload input time is unlimited.

<code>LimitRequestBody 0</code>

The LimitRequestBody variable is an Apache webserver configuration and this restricts the size of POST data. Setting this to 0 means that the POST data is not restricted.

Hopefully the information above will be helpful to anyone trying to upload large documents through a HTML form in a browser.