Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is php.ini upload_max_filesize combined?

Is upload_max_filesize for one single file or for multiple files?

For example, if the property is set to upload_max_filesize: 5M, is it possible to upload three single files which are 2 MB each (for a total of 6MB)? Or will that not work because upload_max_filesize is set to 5MB?

I've been doing some tests but I would like to know the community's perspective.

like image 668
alexpereap Avatar asked Oct 14 '14 22:10

alexpereap


Video Answer


2 Answers

Use post_max_size to set the total and upload_max_filesize for max per file.

Check: https://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize

  • upload_max_filesize int - The maximum size of an uploaded file. When an int is used, the value is measured in bytes. Shorthand notation, as described in this FAQ, may also be used.

And https://www.php.net/manual/en/ini.core.php#ini.post-max-size

  • post_max_size int - Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize. Generally speaking, memory_limit should be larger than post_max_size. When an int is used, the value is measured in bytes. Shorthand notation, as described in this FAQ, may also be used. If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. <form action="edit.php?processed=1">, and then checking if $_GET['processed'] is set.
like image 119
Ingmar Boddington Avatar answered Oct 17 '22 20:10

Ingmar Boddington


I can confirm that upload_max_filesize is the maximum size per file.

e.g. with upload_max_filesize=2M, you can upload 3 files of 1.5M.

I just confirmed this by testing.


Limits you should care about:

  • upload_max_filesize (default 2M): max size per individual file;
  • max_file_uploads (default 20): max number of files you can send per request;
  • post_max_size (default 8M): max raw POST data size per request;
    post_max_size must be greater than the sum of the sizes of:
    • all uploaded files
    • all data in other POST fields
    • a few extra KB to account for the multipart/form-data overhead (headers/boundaries) that wrap every single file and every single POST field in the payload.

Be really careful with these limits, as PHP will not error if you exceed one of them; instead, you'll end up with partial or empty $_POST or $_FILES and might have a hard time debugging the issue.

For example, max_file_uploads will silently ignore any file past the nth uploaded file, and you'll end up with a truncated list of files with no warning whatsoever.

like image 25
BenMorel Avatar answered Oct 17 '22 21:10

BenMorel