Bottom-line:
Do I need to be concerned about setting post_max_filesize
>> memory_limit
?
Details:
This answer suggests that uploaded files do not need to fit within php’s memory_limit. The php docs suggest that the entire post should fit within php’s memory limit.
I find the docs surprising and I’m hoping someone can elaborate. For example take the following php configs:
; config A
memory_limit = 50M
upload_max_filesize = 100M
post_max_filesize = 1000M
max_file_uploads = 10
and
; config B
memory_limit = 50M
upload_max_filesize = 10M
post_max_filesize = 1000M
max_file_uploads = 100
With these configurations I’d expect to be able to:
This experience would lead me to say that "generally the memory_limit should be larger than the upload_max_filesize
"; instead, the php docs say:
generally speaking, memory_limit should be larger than
post_max_size
.
Why and what happens if it isn't?
When my php code is executed I see no evidence that all of the posted files are in memory. It seems to me that all I’ve got is a $_FILES array of paths to files found exclusively on disk. Is php holding the whole post in memory at some point prior to my ability to introspect the environment? Do I need to be concerned about setting post_max_filesize
>> memory_limit
?
Aside:
Violating the manual's rule does not result in a grossly broken server (w/ php5.3 apache2.2 debian 6).
upload_max_filesize is the maximum size of an uploaded file. This is the limit for a SINGLE file. post_max_size, on the other hand, is the limit of the entire body of the request (which may include multiple files as well as other stuff).
To increaes file upload size in PHP, you need to modify the upload_max_filesize and post_max_size variable's in your php. ini file. In addition, you can also set the maximum number of files allowed to be uploaded simultaneously, in a single request, using the max_file_uploads .
The default PHP values are 2 MB for upload_max_filesize, and 8 MB for post_max_size.
PHP will accept uploaded files that are individually smaller than upload_max_filesize
and together take less than post_max_size
bytes. The PHP documentation is wrong with regard to memory_limit
which does not need to hold the file contents posted.
The following configuration works with both Apache2 module and CGI, and accepts files smaller than 1G.
upload_max_filesize = 1G
post_max_size = 1G
memory_limit = 32M
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With