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.
max_file_uploads
in php.ini setting was the cause. Change it to what you want and it will work.
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.
Check your php.ini settings for post_max_size
Also
upload_max_filesize
memory_limit
max_execution_time
max_input_time
Similar to Fosco's solution, but works differently (uses sizeof and a int to int comparison instead of an isset)
Neither this nor his are necessarily any better, just different ways to tackle the problem.
for($i = 0, $size = sizeof($image['name']); $i < $size; $i++)
{
//code
}
And no, it doesn't run sizeof()
each iteration. That's an easy way to screw over performance.
精彩评论