PHP post_max_size vs upload_max_filesize,有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23686505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:52:47  来源:igfitidea点击:

PHP post_max_size vs upload_max_filesize, what is the difference?

php

提问by Tony M

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

当尝试PDF通过为此创建的管理区域上传15mb的文件时,没有任何反应。没有成功或错误消息,但PDF没有上传。

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

然后我认为这可能是php.ini设置的问题。果然,我查看文件的时候,发现限制设置为8m。我假设这意味着 8mb。

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

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

上传最大文件大小: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 POSTdata. 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_filesizeor post_max_size? Does it fall under both? Does one take precedence? Are there cases where one would be used and not the other?

查看评论,似乎一个用于上传文件,而另一个与POST数据直接相关。我对这种情况感到困惑:如果您的表单POST将图像发送到另一个页面,那算什么,upload_max_filesize或者post_max_size?它属于两者吗?一个人优先吗?是否存在使用一种而不使用另一种的情况?

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:

因此,如果我有一个包含 3 个文件输入的表单,所有文件都允许 20mb 或更小,则必须像这样设置设置:

upload_max_filesize = 20M
post_max_size = 60M

回答by Brad

You are correct. post_max_sizeis 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.

你是对的。 post_max_size是所有 POST 正文数据的最大大小。无论您是 POST JSON 还是您的 DVD 收藏,这都是 POST 正文数据。您的文件上传计入此限制。您还应该注意,如果您要上传多个文件,则总文件大小必须符合此限制。

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

upload_max_filesize仅适用于已发布的文件的最大大小。其他类型的 POST 正文数据不受此限制。

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

总之,如果你想上传大文件,你必须增加这两个限制。

回答by Neo

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.

post_max_size 就像超集。upload_max_filesize 与文件上传有关,但 post_max_size 会检查所有类型的 POST 数据。它可以是一个非常大的可以发布的内容,受 post_max_size 的限制。因此,对于要上传的大文件,您需要更改这两个限制。