0

When I try to upload four or less than four files, it's working fine. But when I try to upload more than four files, I am getting the following error:

Warning: Invalid argument supplied for foreach() in C:\wamp\www\multiple-file-upload-with-php\index.php on line 16 Notice: Undefined index: files in C:\wamp\www\multiple-file-upload-with-php\index.php on line 16 

I'm using the following HTML:

 <!-- Multiple file upload html form--> <form action="" method="post" enctype="multipart/form-data"> <input type="file" name="files[]" multiple="multiple" accept="image/*"> <input type="submit" value="Upload"> </form> 

and PHP:

if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){ $valid_formats = array("jpg", "png", "gif", "zip", "bmp"); $max_file_size = 1024*100; //100 kb $path = "uploads/"; // Upload directory $count = 0; // Loop $_FILES to execute all files foreach ($_FILES['files']['name'] as $f => $name) { if ($_FILES['files']['error'][$f] == 4) { continue; // Skip file if any error found } if ($_FILES['files']['error'][$f] == 0) { if ($_FILES['files']['size'][$f] > $max_file_size) { $message[] = "$name is too large!."; continue; // Skip large files } elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){ $message[] = "$name is not a valid format"; continue; // Skip invalid file formats } else{ // No error found! Move uploaded files if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name)) { $count++; // Number of successfully uploaded files } } } } } 

What might be the problem?

1

1 Answer 1

1

Edit your php.ini file and do the changes as shown below :

max_file_uploads=20 

Refer this : http://php.net/manual/en/ini.core.php

Also change these things :

upload_max_filesize = 100M post_max_size = 100M 

Cheers :-)

Sign up to request clarification or add additional context in comments.

6 Comments

max_file_uploads is also important ;)
Yes ofcourse, Sorry I missed to mention it. Thank you Raphael
Doesn't look like an answer, you don't know whether he has this config already or not. Looks more like a wild guess.
changed "post_max_size = 100M" in php.ini and it really works like a charm :). Thank you once again
You are welcome :-), Chilion: yes it was a not a wild guess, I had faced this issue before, Strange but true. Once I change the post_max_size. I worked.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.