1. Home
  2. PHP
  3. Increasing max file upload size

Increasing max file upload size

Overview

By default, file uploads are restricted to less than 32 MB, on a server-by-server basis, to prevent abuse by unauthorized activity. If you need a larger allowance, a few variables are necessary to tune.

Solution

Allowing larger file uploads consists of three tunable variables. These variables may be tuned either through an .htaccess or ini_set. For simplicity, the following example will assume adjustment in a .htaccess file.

Only upload_max_filesize, post_max_size, and memory_limit are relevant tunable parameters. max_execution_time and max_input_time do not affect uploads.

upload_max_filesize: controls the maximum file upload size permitted in a form. This can be suffixed with “m” to denote a size in megabytes, e.g. php_value upload_max_filesize 32m

post_max_size: a sum of all parameters submitted by a form. As a general rule: this should be approximately 33% more than upload_max_filesize, e.g. php_value most_max_size 42m

Explanation: all submitted file uploads are transcoded to base64, which results in approximately a 33% increase in actual consumption (over initial input). Therefore, simply, if an upload is 6 MB, anticipate an actual input of ~ 9 MB. This value must be higher than upload_max_filesize because there are control variables that dictate the file upload constraints (session variables) that must be included in transmission. post_max_size must accommodate upload_max_filesize x 33% + input vars, which typically occupy only a few hundred kilobytes.

memory_limit: this is a non-tunable parameter, without justification,  By default, limits are set to 96 MB on pre-v6 platforms and 192 MB on v6+ platforms. memory_limit affects the amount of memory a PHP script may occupy, in addition to file buffers that may be loaded into memory (think file_get_contents swallowing a file; fread would only buffer up to n bytes so long as temporary variable storage is recycled in an iterative loop!). Depending upon implementation, memory_limit may have no impact on file uploads. It succinctly boils down to the maxim of “don’t do bad things”; don’t write crappy code!

If you are at the mercy of crappy code, open a ticket for us within the control panel to take a look at it and determine a reasonable course of action. We’ll perform an appraisal of your situation, and in most situations, raise your memory limit.

 

Updated on July 8, 2019

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help! If you get an error, visit https://lithiumhosting.com/support instead.
Contact Support