PHP post_max_size 覆盖 upload_max_filesize

发布于 2024-12-09 22:13:59 字数 269 浏览 0 评论 0原文

在我的网站主机中,我(通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

虐人心 2024-12-16 22:13:59

upload_max_filesize 是任何单个文件的限制。
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

如何识别超过 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 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.

梦里的微风 2024-12-16 22:13:59

通过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.

无可置疑 2024-12-16 22:13:59

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

顺便说一句,memory_limit 也发挥了作用。它应该大于 16Mb,但由于默认值为 128Mb,因此您不会看到此问题。示例 php.ini 配置:

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

如果您有权访问 php.ini 中的这些值,则更改它们,否则您可以尝试在 .htaccess< 中更改它们/代码> 文件。

php_value upload_max_filesize 16M
php_value post_max_size 16M 

仅当 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. Example php.ini configuration:

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

Change these value in php.ini if you've access to it, otherwise you can try to change them in an .htaccess file.

php_value upload_max_filesize 16M
php_value post_max_size 16M 

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

£冰雨忧蓝° 2024-12-16 22:13:59

post_max_size:

  • 设置允许的发布数据的最大大小。这个设置也会影响文件上传
  • 要上传大文件,这个值必须大于upload_max_filesize
  • 一般来说,memory_limit应该大于post_max_size。
  • PHP 默认:8M

upload_max_filesize:

  • 上传文件的最大大小
  • PHP 默认:2M

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:

  • 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:

  • The maximum size of an uploaded file
  • PHP Default: 2M

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

奶茶白久 2024-12-16 22:13:59

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

引自PHP 官方网站

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

  2. memory_limit 应大于 post_max_size

您应始终将 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:

  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

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

べ繥欢鉨o。 2024-12-16 22:13:59

更改 php.ini max_input_vars 1000

change in php.ini max_input_vars 1000

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文