PHP 一次只能看到 20 个上传文件

2022-08-30 22:03:51

当我尝试一次上传超过20个文件时,Web服务器只看到前20个。任何其他文件都将被忽略。问题出在哪里?

要尝试的简单代码:

<form action="index.php" method="post" enctype="multipart/form-data">
<?php
if($_FILES){
    print_r($_FILES);
}
else{
    for($i = 0; $i < 30; $i++)
    {
        echo '<input type="file" name="file'.$i.'"><br/>';
    }
}
?>
<input type="submit" value="go">
</form>

print_r()输出:

Array ( [file0] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpD42.tmp [error] => 0 [size] => 274217 ) [file1] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpD52.tmp [error] => 0 [size] => 274217 ) [file2] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpD73.tmp [error] => 0 [size] => 274217 ) [file3] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpD83.tmp [error] => 0 [size] => 274217 ) [file4] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpD94.tmp [error] => 0 [size] => 274217 ) [file5] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpDB4.tmp [error] => 0 [size] => 274217 ) [file6] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpDC5.tmp [error] => 0 [size] => 274217 ) [file7] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpDE5.tmp [error] => 0 [size] => 274217 ) [file8] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpDF5.tmp [error] => 0 [size] => 274217 ) [file9] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpE06.tmp [error] => 0 [size] => 274217 ) [file10] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpE26.tmp [error] => 0 [size] => 274217 ) [file11] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpE37.tmp [error] => 0 [size] => 274217 ) [file12] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpE57.tmp [error] => 0 [size] => 274217 ) [file13] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpE68.tmp [error] => 0 [size] => 274217 ) [file14] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpE78.tmp [error] => 0 [size] => 274217 ) [file15] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpE98.tmp [error] => 0 [size] => 274217 ) [file16] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpEB9.tmp [error] => 0 [size] => 274217 ) [file17] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpEC9.tmp [error] => 0 [size] => 274217 ) [file18] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpEE9.tmp [error] => 0 [size] => 274217 ) [file19] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:\tmp\phpEFA.tmp [error] => 0 [size] => 274217 ) )

.htaccess: php_value max_file_uploads 100 - 无济于事

ini_set('max_file_uploads', 100) - doesn't help

我刚刚在我的本地服务器上添加了php.ini行:

max_file_uploads = 100

而且它很有帮助。但我不认为托管商在客户端的Web服务器上更改它。如果不进行编辑,此值将是非常酷的效果。php.ini


答案 1

最大文件上传次数设置设置设置得更高(是的,这是一个“新”设置)。

它是PHP_INI_SYSTEM,因此可以在php.ini或webserver/apache配置中设置。恐怕没有或“脚本内”访问。.htaccess


答案 2

最近我遇到了同样的问题,但不幸的是,上述解决方案都不适合我。因此,我认为我必须在这里分享工作解决方案

当我尝试上传50多张图片时,服务器将其限制为20张。(我正在使用 PHP 5.3.6 的 Centos 服务器工作)

PHP中的设置.ini文件甚至没有帮助,但文件上传限制更改为25max_file_uploads = 100

在phpinfo()页面中搜索数值25时,我遇到了一个参数suhosin.upload.max_uploads,值为25。

将 suhosin.upload.max_uploads 设置为 100 以及在 PHP.ini 文件工作正常,现在在服务器上我们最多可以上传 100 个文件。(我不确定我们是否有任何其他文件修改了 suhosin 参数的值 ,但是在 php.ini 或 php.d/suhosin 中设置 suhosin 值.ini将:))max_file_uploads = 100

max_file_uploads = 100    
suhosin.upload.max_uploads=100

http://www.hardened-php.net/suhosin/configuration.html


推荐