PHP 一次只能看到 20 个上传文件
当我尝试一次上传超过 20 个文件时,网络服务器只能看到前 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
它有帮助。但我不认为托管商会在客户端的网络服务器上更改它。无需编辑 php.ini
即可对该值产生非常酷的效果。
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?
Simple code to try:
<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()
output:
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 - doesn't help
ini_set('max_file_uploads', 100) - doesn't help
I just added line to php.ini on my local server :
max_file_uploads = 100
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
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
设置最大文件上传数设置更高(是的,这是一个“新”设置)。
它是 PHP_INI_SYSTEM,因此可以在 php.ini 中设置或网络服务器/apache 配置。恐怕没有
.htaccess
或“脚本内”访问权限。Set the max-file-uploads setting higher (yes, it's a 'newish' setting).
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.最近我遇到了同样的问题,但不幸的是上述解决方案都不适合我。所以我想我必须在这里分享有效的解决方案
当我尝试上传 50 多个图像时,服务器将其限制为 20。(我正在使用 PHP 5.3.6 的 Centos 服务器上工作)
设置
max_file_uploads = 100< PHP.ini 文件中的 /code> 甚至没有帮助,但文件上传限制数量更改为 25
在 phpinfo() 页面中搜索数值 25 时,我遇到了一个参数suhosin.upload.max_uploads 的值为 25。
将 suhosin.upload.max_uploads 设置为 100 以及 PHP.ini 文件中的
max_file_uploads = 100
有效,现在在服务器上我们最多可以上传 100 个文件。 (我不确定我们是否有任何其他文件可以修改 suhosin 参数的值,但在 php.ini 或 php.d/suhosin.ini 中设置 suhosin 值将起作用:) )http://www.hardened-php.net/suhosin/configuration.html
Recently I came across the same issue, but unfortunately none of the above solutions worked for me. So I think I must share the worked solution here
When I was trying to upload 50+ images, the server was limiting it to 20. (I was working on a Centos Server with PHP 5.3.6)
Setting
max_file_uploads = 100
in PHP.ini file didn't help even but the number file upload limit changed to 25On searching the numeric value 25 in the phpinfo() page, I came across a parameter suhosin.upload.max_uploads with value 25.
Setting suhosin.upload.max_uploads to 100 along with
max_file_uploads = 100
in the PHP.ini file worked, now on the server we can upload upto 100 files. (I am not sure if we have any other file where we modify the values suhosin parameters , but setting suhosin values in either php.ini OR php.d/suhosin.ini will work :) )http://www.hardened-php.net/suhosin/configuration.html
PHP 可以发布的数量是有限制的。请参阅upload_max_filesize,max_file_uploads 和 post_max_size 指令。
There are limits as to how much PHP can post. See the upload_max_filesize, max_file_uploads, and post_max_size directives.
您可能会遇到 post_max_size或 upload_max_filesize 设置限制。
您可以在 php.ini 中更改它们(post_max_size 应大于 upload_max_filesize)
You might be running into post_max_size or upload_max_filesize setting limitations.
You can change them in php.ini (post_max_size should be larger than upload_max_filesize)
您可以在托管的网站目录中创建 php.ini 文件,并在其中写入以下内容:
据我尝试,这是允许在大多数主机上覆盖 php.ini 的方法(但不在本地主机 XAMP 等中)
You can create php.ini file in your website directory on hosting, and write this in it:
This is allowed way to overwrite php.ini on most hostings (but not in localhost XAMP, etc.) as far as I tried
如果您将 PHP 作为 Apache 模块运行,您可能需要在虚拟主机级别更改它(又名
httpd.conf
)。您需要记住,作为PHP_INI_SYSTEM
指令,您必须使用 php_admin_value (常规 php_value 将被忽略)。示例代码可以是:If you run PHP as Apache module you might want to change it at virtual host level (aka
httpd.conf
). You need to remember that, being aPHP_INI_SYSTEM
directive, you have to use php_admin_value (regular php_value will be ignored). Sample code could be:第 1 步:如果您使用 Xampp 服务器在 localhost 上工作,则打开 xampp 控制面板
单击配置按钮然后打开 php.ini
步骤 2:找到 max_file_uploads=20
步骤 3:将值 20 更改为自定义值
步骤 4:保存此 php.ini 文件并关闭
第 5 步:通过单击“停止”重新启动 Apache 服务器,然后单击“开始”等待绿色背景意味着 apache 已成功启动
通过使用代码上传文件进行最终测试
Step 1: If you are working on localhost with Xampp server than open xampp control panel
click on config button than open php.ini
Step 2: find max_file_uploads=20
Step 3: Change value 20 with custom value
Step 4: Save this php.ini file and close
Step 5: restart your Apache server by clicking stop and than click on start wait for green color background means apache started successfully
Final test by uploading file using your code
max_file_uploads
配置选项将限制设置为 20。http://de3.php.net/manual /en/ini.core.php#ini.max-file-uploads
There is a limit set to 20 by the
max_file_uploads
configuration option.http://de3.php.net/manual/en/ini.core.php#ini.max-file-uploads
apache文件夹路径中还有另一个php.ini,路径是/etc/php/7.4/apache2/php.ini。在 php.ini 中编辑 max_file_uploads = 500,然后重新启动 apache。它肯定会起作用
There is another php.ini inside apache folder path would be /etc/php/7.4/apache2/php.ini. Edit in thi php.ini as max_file_uploads = 500 and then restart apache. It will Work for sure
您可以设置 .htaccess 或 php.ini 文件。 不起作用
有时 ini_set在 .htaccess 文件中 。添加以下行,
您必须设置 upload_max_filesize & post_max_size 基于上传的文件数量。
示例:100(图像)& 3MB(每个图像大小)= 300MB(总大小)
You can set either .htaccess or php.ini files. sometimes not going to work ini_set
in .htaccess file. Add below lines
you have to set upload_max_filesize & post_max_size based on number of files uploading.
example: 100 (Images) & 3MB (Per Image size) = 300MB (Total Sizes)