user1098063
user1098063

Reputation:

Looping over multi-upload form fields

I have a multi-file upload form in PHP. I loop over the file input boxes like so:

while(list($key,$value) = each($_FILES['images']['name']))

I added a description box, so now I have description[] as another field.

How can I loop over both the files and the description boxes?

Upvotes: 1

Views: 177

Answers (3)

Baba
Baba

Reputation: 95101

You can try working on both simultaneously

foreach ( $_FILES ['image'] ['tmp_name'] as $key => $val ) {
    $fileName = $_FILES ['image'] ['name'] [$key]; // FileName
    $fileDesc = $_POST['description'][$key]; // Work on Description
}

Upvotes: 1

zanlok
zanlok

Reputation: 1630

You should to iterate: foreach( $_FILES as $file ) { ... }

Upvotes: 0

Krishna Deepak
Krishna Deepak

Reputation: 1765

Most probably both have correspondily same keys. So

foreach($_FILES['images']['name']) as $k=>$v)
{
    echo $v."<br>";
    echo $description[$k]."<br>";
}

Upvotes: 0

Related Questions