Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP see only 20 uploading files at a time

Tags:

file

php

upload

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.

like image 674
Alex Avatar asked May 21 '11 16:05

Alex


People also ask

How many files can PHP upload?

When you are working with multiple files upload in PHP, it is necessary to increase the maximum number of files to upload. By default, you can upload 20 files via a single request. If you want to upload more than 20 files, you should need to modify the max_file_uploads variable value in php. ini file.


2 Answers

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.

like image 171
Wrikken Avatar answered Oct 02 '22 10:10

Wrikken


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 25

On 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 :) )

max_file_uploads = 100    
suhosin.upload.max_uploads=100

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

like image 38
Hari Swaminathan Avatar answered Oct 02 '22 12:10

Hari Swaminathan