PHP post_max_size 覆盖 upload_max_filesize
在我的网站主机中,我(通过 phpinfo)看到
- post_max_size = 8Mb
- upload_max_filesize = 16Mb
这让我认为我应该能够上传 16Mb 大的文件。 然而,当我通过 post 方法(正常情况下)执行此操作时,post_max_size 接管并声明我发送了太多。
允许发送 16Mb 大文件的方法是什么? 获取-放置-其他?
希望有人能为我澄清这一点。
西蒙
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
upload_max_filesize
是任何单个文件的限制。post_max_size
是请求整个正文的限制,其中可能包含多个文件。给定
post_max_size = 20M
和upload_max_filesize = 6M
,您最多可以上传 3 个文件,每个文件大小为 6M。如果改为post_max_size = 6M
和upload_max_filesize = 20M
,那么您在达到 post_max_size 之前只能上传一个 6M 文件。upload_max_size
> 没有帮助。post_max_size
。如何识别超过
post_max_size
并不明显。$_POST
和$_FILES
将为空,但$_SERVER['CONTENT_LENGTH']
将 > 0. 如果客户端没有上传任何 post 变量或文件,则$_SERVER['CONTENT_LENGTH']
将为 0。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
andupload_max_filesize = 6M
you could upload up to 3 files of 6M each. If insteadpost_max_size = 6M
andupload_max_filesize = 20M
then you could only upload one 6M file before hitting post_max_size. It doesn't help to haveupload_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.通过POST方式完成文件上传(通常也有其他方法)。查看包含文件上传字段的表单的方法属性;)
任何相关设置的最低限制都会取代较高的设置:
请参阅处理文件上传:常见陷阱详细解释了这一点以及如何计算价值观。
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:
See Handling file uploads: Common Pitfals which explains this in detail and how to calculate the values.
发送文件上传的正常方法是 POST,因此
post_max_size
也应为 16 Mb 或更大。顺便说一句,
memory_limit
也发挥了作用。它应该大于 16Mb,但由于默认值为 128Mb,因此您不会看到此问题。示例php.ini
配置:如果您有权访问
php.ini
中的这些值,则更改它们,否则您可以尝试在.htaccess< 中更改它们/代码> 文件。
仅当
AllowOverride
设置允许时,此功能才有效。否则,您必须询问您的托管公司。The normal method to send a file upload is POST, thus also
post_max_size
should be 16 Mb or more.Incidentally, also
memory_limit
plays a role. It should be bigger than 16Mb, but since the default value is 128Mb, you won't see this problem. Examplephp.ini
configuration:Change these value in
php.ini
if you've access to it, otherwise you can try to change them in an.htaccess
file.This will work only if the
AllowOverride
settings permit it. Otherwise, you've to ask to your hosting company.post_max_size:
upload_max_filesize:
post_max_size > upload_max_filesize
PHP 默认:128M > 8M> 2M
默认情况下,post_max_size 应大于 upload_max_filesize 的 4 倍。
依次
memory_limit 应大于 post_max_size 的 16 倍
post_max_size:
upload_max_filesize:
memory_limit > post_max_size > upload_max_filesize
PHP Default: 128M > 8M > 2M
By default, post_max_size should be 4 times greater than upload_max_filesize.
In turn
memory_limit should be 16 times greater than post_max_size
您的服务器配置设置允许用户上传最大 16MB 的文件(因为您已设置 upload_max_filesize = 16Mb),但是 post_max_size 仅接受最大 8MB 的发布数据。这就是它抛出错误的原因。
引自PHP 官方网站:
您应始终将 post_max_size 值设置为大于 upload_max_filesize 值。
Your server configuration settings allows users to upload files upto 16MB (because you have set upload_max_filesize = 16Mb) but the post_max_size accepts post data upto 8MB only. This is why it throws an error.
Quoted from the official PHP site:
You should always set your post_max_size value greater than the upload_max_filesize value.
更改 php.ini
max_input_vars 1000
change in php.ini
max_input_vars 1000