Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Input: uploading multiple files maxes at 20

I have an html input field, such as

<form method="post" action="process.php" enctype="multipart/form-data">
    <div>
        <h3>Files:</h3>
        <input type="file" multiple="multiple" name="image[]" />
        <input type="submit" value="Upload Image" />
    </div>
</form>

And I want the user to be able to upload multiple files at once. My php for this uses a for loop to cycle through all the files, gathers information on each one, and then uploads them one by one.

for($i = 0;$image['name'][$i] == true;$i++)
{
    //code
}

But this won't upload more than 20, ending with an error, Notice: Undefined offset: 20 in F:\www\hdp\process.php on line 39. Now, if I were to upload 5 images, it would give me Notice: Undefined offset: 5 in F:\www\hdp\process.php on line 39, but that would be ok because it would still upload all 5 photos (0,1,2,3,4). I need it to upload all the photos the user adds.
I know uploading lots of files at once could be a bad idea, but it is just the site admin, and it's a photography portfolio site. So he needs to be able to upload a lot of photos at once. And if it's important, they are being uploaded to a MySQL database.

like image 460
DavidR Avatar asked Dec 13 '22 12:12

DavidR


2 Answers

max_file_uploads in php.ini setting was the cause. Change it to what you want and it will work.

like image 148
Justinas Jaronis Avatar answered Dec 15 '22 01:12

Justinas Jaronis


I'm a bit confused by the 'wont upload more than 20' part... what are you basing this on? You're getting an error either way it seems.

Change your for loop to check for isset($image['name'][$i]) instead, and you will no longer get an error.

for($i = 0; isset($image['name'][$i]); $i++)
{
    //code
}

As mentioned by yes123, you risk hitting the maximum POST size and should check php.ini.

like image 36
Fosco Avatar answered Dec 15 '22 02:12

Fosco