Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP post_max_size overrides upload_max_filesize

In my site host, I have seen (via phpinfo) that

  • post_max_size = 8Mb
  • upload_max_filesize = 16Mb

This led me to think that I should be able to upload as file as big as 16Mb. However, when I do this through a post method (as normal), post_max_size takes over and declares that I sent too much.

What is the method which permits sending a file as big as 16Mb ? GET - PUT - other ?

Hope someone can clarify this for me.

Simon

like image 624
Simon Avatar asked Oct 13 '11 12:10

Simon


People also ask

What is upload_max_filesize and Post_max_size?

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).

How do I change the maximum upload file size in PHP?

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 .


2 Answers

upload_max_filesize is the limit of any single file. post_max_size is the limit of the entire body of the request, which could include multiple files.

Given post_max_size = 20M and upload_max_filesize = 6M you could upload up to 3 files of 6M each. If instead post_max_size = 6M and upload_max_filesize = 20M then you could only upload one 6M file before hitting post_max_size. It doesn't help to have upload_max_size > post_max_size.

It's not obvious how to recognize going over post_max_size. $_POST and $_FILES will be empty, but $_SERVER['CONTENT_LENGTH'] will be > 0. If the client just didn't upload any post variables or files, then $_SERVER['CONTENT_LENGTH'] will be 0.

like image 197
Matthew Avatar answered Oct 20 '22 08:10

Matthew


By POST file uploads are done (commonly, there are also other methods). Look into the method attribute of the form which contains the file-upload field ;)

The lowest limit of any related setting supersedes a higher setting:

  • post_max_size
  • upload_max_filesize
  • memory_limit

See Handling file uploads: Common Pitfals which explains this in detail and how to calculate the values.

like image 21
hakre Avatar answered Oct 20 '22 08:10

hakre