41

When trying to upload a PDF file that was 15mb through an admin area created for doing so, nothing happened. There was no success or error message, but the PDF did not upload.

I then thought that it could be an issue with the php.ini settings. Sure enough, when I looked at the file, I found that the limits were set to 8m. Which I'm assuming means 8mb.

post_max_size: http://php.net/post-max-size

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
post_max_size = 20M

upload_max_filesize: http://php.net/upload-max-filesize

; Maximum allowed size for uploaded files.
upload_max_filesize = 20M

Looking at the comments, it appears that one is for files being uploaded, while the other relates directly to POST data. What I'm confused about is this scenario: If you have a form that is POST'ing an image to another page, what does that count as, upload_max_filesize or post_max_size? Does it fall under both? Does one take precedence? Are there cases where one would be used and not the other?

Edit:

So if I have a form that has 3 file inputs, all allowing files 20mb or smaller, the settings would have to be set like so:

upload_max_filesize = 20M
post_max_size = 60M

2 Answers 2

53

You are correct. post_max_size is the maximum size for all POST body data. It doesn't matter if you're POSTing JSON or your DVD collection, this is all POST body data. Your file upload counts towards this limit. You should also be aware that if you are uploading multiple files, the total file size has to fit within this limit.

upload_max_filesize is a maximum size only for files that are POSTed. Other types of POST body data are not subject to this limit.

In short, if you want to upload large files, you must increase both limits.

4
  • 1
    Your webserver may also have a limit. Apache has the LimitRequestBody directive, which could be set. If its present it has to be equal to or larger than post_max_size
    – Oscar M.
    May 15, 2014 at 19:04
  • 3
    So from what I understand if I have a form that has 3 uploads with caps at 20mb it would be fine to have upload_max_filesize = 20M but post_max_size would have to be set to 60M?
    – Tony M
    May 15, 2014 at 19:07
  • 2
    @Brad But a post with a file is bigger than the file itself (due to mime separators, other parameters, etc) so 3 files of 20 MB each, when uploaded they will have a total size = 60MB + "some additional data coming from other parameters, mime encoding"...right?
    – Alex
    May 10, 2017 at 13:20
  • @Alex Correct. I should have clarified in my comment... I was trying to keep it simple. Realistically, almost nobody is going to upload 3 files in exactly 20MB of size, so this isn't an issue. Unless of course you have a place where that's what they do.
    – Brad
    May 10, 2017 at 14:05
7

post_max_size is like the superset. upload_max_filesize is in context with file uploads but post_max_size is checked for all kind of POST data. It can be a very big content which can be posted which is limited by post_max_size. So for a big file you want to upload, you need to change both the limits.

2
  • 2
    From the docs for post_max_size: "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."
    – Sam
    May 15, 2014 at 19:02
  • 1
    @Sam I think that what Neo tried to bring attention to is that post_max_size size must contain all files but should be bigger (than the sum of all uploaded files) as it can contain much more (parameters, MIME delimiters, etc)
    – Alex
    May 10, 2017 at 13:24

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.