Skip to content

Blog

Large file uploading

Author: Justin Munro

Recently we had an issue with our web design 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:

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

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.

php_value max_execution_time 3600

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

php_value upload_max_filesize 500M

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.

php_value post_max_size 500M

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.

php_value memory_limit -1

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.

php_value max_input_time -1

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.

LimitRequestBody 0

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. Find out more about our bespoke web development.