19

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.

Ajean
  • 5,528
  • 14
  • 46
  • 69
Alex
  • 191
  • 1
  • 1
  • 4

10 Answers10

18

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.

Wrikken
  • 69,272
  • 8
  • 97
  • 136
  • I did. But thats allways equal 20 ) – Alex May 21 '11 at 17:21
  • ini_set('max_file_uploads', 22); echo ini_get('max_file_uploads'); – Alex May 21 '11 at 17:21
  • .htaccess : php_value max_file_uploads 100 doesn't help too – Alex May 21 '11 at 17:23
  • 1
    It's [PHP_INI_SYSTEM](http://www.php.net/manual/en/configuration.changes.modes.php), so it can either be set in php.ini or webserver/apache configuration. No `.htaccess` or 'in-script' access I'm afraid. – Wrikken May 22 '11 at 08:10
9

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

Hari Swaminathan
  • 616
  • 1
  • 13
  • 27
  • THANK YOU! This was the problem for me too. – Don Rhummy Apr 28 '14 at 18:46
  • For some reason my Hostinger server was ignoring my max_file_uploads and limiting to 20 files at a time when I initially set it to 1000, so I changed it to 950 and now it's working ok... weird stuff happens sometimes... +1 – Jesús Hagiwara Feb 23 '23 at 16:31
2

There are limits as to how much PHP can post. See the upload_max_filesize, max_file_uploads, and post_max_size directives.

onteria_
  • 68,181
  • 7
  • 71
  • 64
1

You can create php.ini file in your website directory on hosting, and write this in it:

max_file_uploads = 400

This is allowed way to overwrite php.ini on most hostings (but not in localhost XAMP, etc.) as far as I tried

Mladen Janjetovic
  • 13,844
  • 8
  • 72
  • 82
1

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 a PHP_INI_SYSTEM directive, you have to use php_admin_value (regular php_value will be ignored). Sample code could be:

<Location "/api">
    php_admin_value max_file_uploads 250
</Location>
Álvaro González
  • 142,137
  • 41
  • 261
  • 360
1

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

Shreenivas
  • 11
  • 1
1

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)

jm_toball
  • 1,207
  • 8
  • 10
0

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

Alex
  • 32,506
  • 16
  • 106
  • 171
0

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

0

You can set either .htaccess or php.ini files. sometimes not going to work ini_set

in .htaccess file. Add below lines

php_value upload_max_filesize 400M
php_value post_max_size 400M
php_value max_file_uploads 100

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)

rsmdh
  • 128
  • 1
  • 2
  • 12