HTML input: loading multiple maxes files at 20

I have an html input field like

<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 loop forto cycle through all files, collect information on each of them and then load them one at a time.

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

But it will not load more than 20, ending mistake Notice: Undefined offset: 20 in F:\www\hdp\process.php on line 39. Now, if I uploaded 5 images, that would give me Notice: Undefined offset: 5 in F:\www\hdp\process.php on line 39, but that would be normal, because he uploaded all 5 photos anyway (0,1,2,3,4). I need to upload all the photos that the user adds.
I know that downloading a large number of files at once may be a bad idea, but this is only the site administrator, and this is a photography portfolio site. Therefore, it should be able to upload many photos at once. And if this is important, they are loaded into the MySQL database.

+3
source share
4 answers

I'm a little confused by the "do not load more than 20" part ... what did you base on this? You get an error anyway.

for, isset ($ image ['name'] [$ i]), .

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

yes123, POST php.ini.

+1

max_file_uploads php.ini . , , .

+10

Check php.ini settings for post_max_size

Besides

upload_max_filesize  
memory_limit 
max_execution_time 
max_input_time
+1
source

Similar to Fosco's solution, but it works differently (uses sizeof and int to compare int instead of isset)

Neither one is necessarily better, just different ways to solve this problem.

for($i = 0, $size = sizeof($image['name']); $i < $size; $i++)
{
    //code
}

And no, it does not start sizeof()every iteration. This is an easy way to screw performance.

0
source

All Articles