PHP post_max_size 覆盖 upload_max_filesize

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7754133/
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-26 03:19:29  来源:igfitidea点击:

PHP post_max_size overrides upload_max_filesize

phpuploadfilesize

提问by Simon

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

在我的网站主机中,我已经看到(通过 phpinfo)

  • post_max_size = 8Mb
  • upload_max_filesize = 16Mb
  • 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.

这让我觉得我应该能够上传 16Mb 的文件。但是,当我通过 post 方法(正常情况下)执行此操作时,post_max_size 接管并声明我发送了太多。

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

允许发送 16Mb 大文件的方法是什么?GET-PUT-其他?

Hope someone can clarify this for me.

希望有人可以为我澄清这一点。

Simon

西蒙

回答by Matthew

upload_max_filesizeis the limit of any single file. post_max_sizeis the limit of the entire body of the request, which could include multiple files.

upload_max_filesize是任何单个文件的限制。 post_max_size是请求整个主体的限制,可以包含多个文件。

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

鉴于post_max_size = 20Mupload_max_filesize = 6M您最多可以上传 3 个 6M 的文件。如果相反post_max_size = 6Mupload_max_filesize = 20M那么您只能在点击 post_max_size 之前上传一个 6M 文件。upload_max_size>没有帮助post_max_size

It's not obvious how to recognize going over post_max_size. $_POSTand $_FILESwill 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.

如何识别 over 并不明显post_max_size$_POSTand$_FILES将是空的,但$_SERVER['CONTENT_LENGTH']会 > 0。如果客户端只是没有上传任何 post 变量或文件,那么$_SERVER['CONTENT_LENGTH']将为 0。

回答by hakre

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

通过 POST 文件上传完成(通常也有其他方法)。查看包含文件上传字段的表单的方法属性;)

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

任何相关设置的最低限制取代更高的设置:

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

请参阅处理文件上传:常见陷阱,其中详细解释了这一点以及如何计算值。

回答by stivlo

The normal method to send a file upload is POST, thus also post_max_sizeshould be 16 Mb or more.

发送文件上传的正常方法是 POST,因此也post_max_size应该是 16 Mb 或更多。

Incidentally, also memory_limitplays a role. It should be bigger than 16Mb, but since the default value is 128Mb, you won't see this problem. Example php.iniconfiguration:

顺便说一句,也memory_limit起了作用。它应该大于 16Mb,但由于默认值是 128Mb,你不会看到这个问题。示例php.ini配置:

post_max_size = 16M
upload_max_filesize = 16M
memory_limit = 128M

Change these value in php.iniif you've access to it, otherwise you can try to change them in an .htaccessfile.

php.ini如果您可以访问这些值,请更改这些值,否则您可以尝试在.htaccess文件中更改它们。

php_value upload_max_filesize 16M
php_value post_max_size 16M 

This will work only if the AllowOverridesettings permit it. Otherwise, you've to ask to your hosting company.

这只有在AllowOverride设置允许时才有效。否则,您必须询问您的托管公司。

回答by N?s????? ?

post_max_size:

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
  • Generally speaking, memory_limit should be larger than post_max_size.
  • PHP Default: 8M
  • 设置允许的帖子数据的最大大小。此设置也会影响文件上传
  • 上传大文件,这个值必须大于upload_max_filesize
  • 一般来说,memory_limit 应该大于 post_max_size。
  • PHP 默认:8M

upload_max_filesize:

上传最大文件大小:

  • The maximum size of an uploaded file
  • PHP Default: 2M
  • 上传文件的最大大小
  • PHP 默认值:2M


memory_limit > post_max_size > upload_max_filesize

memory_limit > post_max_size > upload_max_filesize

PHP Default: 128M > 8M > 2M

PHP 默认值: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

默认情况下,post_max_size 应该是 upload_max_filesize 的 4 倍。
反过来,memory_limit 应该比 post_max_size 大 16 倍

回答by Sai Kiran Sripada

Your server configuration settings allows users to upload files upto 16MB (because you have set upload_max_filesize= 16Mb) but the post_max_sizeaccepts post data upto 8MB only. This is why it throws an error.

您的服务器配置设置允许用户上传最大 16MB 的文件(因为您已设置upload_max_filesize= 16Mb)但post_max_size仅接受最大 8MB 的发布数据。这就是它抛出错误的原因。

Quoted from the official PHP site:

引用自PHP 官方网站

  1. To upload large files, post_max_size value must be larger than upload_max_filesize.

  2. memory_limit should be larger than post_max_size

  1. 要上传大文件,post_max_size 值必须大于upload_max_filesize。

  2. memory_limit 应该大于 post_max_size

You should always set your post_max_size value greater than the upload_max_filesize value.

您应该始终将 post_max_size 值设置为大于 upload_max_filesize 值。

回答by user7224508

change in php.ini max_input_vars 1000

更改 php.ini max_input_vars 1000