17 February 2013

upload_max_filesize/post_max_size experimentation

From my testing on PHP 5.2.0, here is a little information about these two ini settings:
  1. upload_max_filesize refers to the size of the file (no surprise)
  2. post_max_size refers to the size of the post data - also no surprise, but this means the size of the post data not including any on-the-wire encoding.
  3. From 1 and 2, you can assume that post_max_size only needs to be a small amount bigger than upload_max_filesize for a file upload to work, even for large files [1]. BUT, if you need to upload more than one file on any given form, post_max_size will have to be more than double the size, and so on for more files.
  4. Despite what the php.net manual says, the uploaded files are NOT loaded into memory, and so it seems that memory_limit has no effect on whether you can or cannot upload files.
Based on these observations, if your application only allows one file to be uploaded in any one request, and you only want files of up to 50M in size, then safe settings are upload_max_filesize = 50M and post_max_size = 55M. If your application allows multiple files to be uploaded in one request - e.g. you have a mass file upload page that allows 10 files to be uploaded - then more sensible settings might be upload_max_filesize = 50M and post_max_size = 505M.

[1]For a small form, post_max_size only needs to be about 2K bigger for the maximum sized file to be uploaded. Don't forget if you give people a textarea to write in as well they could go on and on and on and on and on and need a bigger limit.


Source: http://nigel.mcnie.name/blog/uploadmaxfilesizepostmaxsize-experimentation

See also: http://www.mediawiki.org/wiki/Manual:Configuring_file_uploads

No comments:

Post a Comment