首页 > 解决方案 > PHP 清空 $_POST 和 $_FILES 并上传大文件

问题描述

请不要将此作为重复项关闭。我知道这里发布了许多类似的问题,但我已经尝试了所有这些答案,但问题没有改变。我已经研究了一个多星期。我找到的所有答案都在谈论我已经正确设置的以下设置。

我的 MAMP 服务器的 php.ini 包括以下内容:

    file_uploads         On
    upload_max_filesize  16700000
    post_max_size        16777216
    memory_limit         768M
    max_input_time       360
    max_execution_time   360

我的 .htaccess 文件重复这些:

    php_value file_uploads         On
    php_value upload_max_filesize  16700000
    php_value post_max_size        16777216
    php_value memory_limit         768M
    php_value max_input_time       360
    php_value max_execution_time   360

并且还有:

LimitRequestBody 16777216 
<IfModule mod_security2.c>
    SecRequestBodyLimit        16777216
    SecRequestBodyNoFilesLimit 16777216
</IfModule>

我的 httd.conf 文件包含相同的设置。

当我在运行时使用 进行检查时ini_get(),我看到了上面给出的 php ini 值,但max_execution_time无论这些设置如何,它始终为 0(无限制)。

使用FormDatain a XMLHttpRequest,如果我上传的文件最大约为 1meg,则 Content-length 标头看起来正确并且一切正常。如果我上传一个稍微大一点的文件,我会看到所有相同的值, Content-length 标头看起来正确(并且小于post_max_size),但是$_POST$_FILES是空的,并且客户端会看到 HTTP status 413 Request Entity Too Large。php 和 apache 日志文件均未显示错误。

更新:

在进一步调查中,我发现Requested content-length of 1829686 is larger than the configured limit of 1024000. apache_ssl_request.log那么这个 1024000 的限制是从哪里来的呢?这是什么境界?find /Applications/MAMP -type f -exec grep -l 1024000 '{}' \;仅找到此错误消息,没有具有此值的配置文件条目。

标签: phplarge-file-upload

解决方案


推荐阅读