Uploading large files in PHP: upload_max_filesize and post_max_size

To upload a big file through a form, two values have to be high enough, and the second has to be larger than the first: upload_max_filesize (the size of each file) and post_max_size (the size of the whole request). If you raise only the first, the upload keeps failing, often without a single message.

The limits that count

Value What it limits
upload_max_filesize The size of each uploaded file.
post_max_size The size of everything the form sends. It must be larger than the one above, so the rest of the form fits too.
memory_limit Should stay above post_max_size, because PHP handles the request in memory.
max_execution_time and max_input_time On slow connections a big file takes a while to arrive. If the time runs out, the upload is cut.
max_file_uploads How many files can go in a single request.

Raising the values

1 In Select PHP Version, Options tab, raise upload_max_filesize and post_max_size, keeping the second higher than the first.
2 If it is for one application only, put the lines in a .user.ini in its folder. See where to set each value.
3 Check what is now in force. A file with the line below, opened in the browser, shows both values. Delete it afterwards.
4 If the application has a limit of its own (WordPress shows its own on the Media upload screen), that is the lowest one and the one that counts. See raising the WordPress upload limit.

<?php echo ini_get('upload_max_filesize'), ' / ', ini_get('post_max_size');

Right limits, upload still failing

Symptom Likely cause
The progress bar reaches the end and then it fails The time ran out (max_execution_time or max_input_time), or the account’s space ran out.
An error with only some files The application refuses certain file types. Look at the type, not the size.
An error while saving the file The destination folder lacks write permission, or the account’s space has run out.
Works in your tests and fails for visitors Their connection is slower and the time runs out before the file arrives.
The silent failure. When a request goes past post_max_size, PHP throws away everything it received: the application sees an empty form, with no error at all, and answers “no file selected” or just returns to the same page. If an upload “does nothing”, this is the first value to check.
Some limits sit outside PHP. If your domain goes through a service such as Cloudflare, that service also caps the body of each request, and the cap depends on its plan. And the account’s space has to be enough for the file.
For very large files, skip the browser. An SFTP transfer can be resumed and does not depend on these limits. See SFTP instead of FTP. For files your visitors upload, an application that splits the file into chunks is more dependable than pushing the limits to the extreme.

Raised both values and the upload still fails? Tell us the page and the size of the file.

Open a support ticket

SEE ALSO

PHP limits: memory, time, upload size and the one that fails silently

Raising the WordPress upload limit

php.ini and .user.ini: where to set a value

SFTP instead of FTP

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from $5.36/mo (3-year plan, with coupon)

See plans
  • 0 Users Found This Useful
Was this answer helpful?