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

2022-01-09 00:00:00 file upload php

当我尝试一次上传超过 20 个文件时,Web 服务器只会看到前 20 个文件.任何其他文件都将被忽略.有什么问题?

When I try to upload more than 20 files at a time, then the web server see only first 20. Any other files are just ignored. What is the problem?

简单代码尝试:

<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:	mpphpD42.tmp [error] => 0 [size] => 274217 ) [file1] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpD52.tmp [error] => 0 [size] => 274217 ) [file2] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpD73.tmp [error] => 0 [size] => 274217 ) [file3] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpD83.tmp [error] => 0 [size] => 274217 ) [file4] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpD94.tmp [error] => 0 [size] => 274217 ) [file5] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpDB4.tmp [error] => 0 [size] => 274217 ) [file6] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpDC5.tmp [error] => 0 [size] => 274217 ) [file7] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpDE5.tmp [error] => 0 [size] => 274217 ) [file8] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpDF5.tmp [error] => 0 [size] => 274217 ) [file9] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpE06.tmp [error] => 0 [size] => 274217 ) [file10] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpE26.tmp [error] => 0 [size] => 274217 ) [file11] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpE37.tmp [error] => 0 [size] => 274217 ) [file12] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpE57.tmp [error] => 0 [size] => 274217 ) [file13] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpE68.tmp [error] => 0 [size] => 274217 ) [file14] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpE78.tmp [error] => 0 [size] => 274217 ) [file15] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpE98.tmp [error] => 0 [size] => 274217 ) [file16] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpEB9.tmp [error] => 0 [size] => 274217 ) [file17] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpEC9.tmp [error] => 0 [size] => 274217 ) [file18] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpEE9.tmp [error] => 0 [size] => 274217 ) [file19] => Array ( [name] => 39442.jpg [type] => image/jpeg [tmp_name] => W:	mpphpEFA.tmp [error] => 0 [size] => 274217 ) )

.htaccess:php_value max_file_uploads 100 - 没有帮助

.htaccess: php_value max_file_uploads 100 - doesn't help

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

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

I just added line to php.ini on my local server :

max_file_uploads = 100

这很有帮助.但我不认为宿主在客户端的网络服务器上改变它.不编辑 php.ini.

And it's helped. But I don't think that the hoster change it on client's web server. It would be very cool effect on this value without editing php.ini.

推荐答案

设置max-file-uploads 设置更高(是的,这是一个新"设置).

Set the max-file-uploads setting higher (yes, it's a 'newish' setting).

它是 PHP_INI_SYSTEM,所以它可以设置在php.ini 或 webserver/apache 配置.恐怕没有 .htaccess 或脚本内"访问权限.

It's PHP_INI_SYSTEM, so it can either be set in php.ini or webserver/apache configuration. No .htaccess or 'in-script' access I'm afraid.

相关文章