user3222494
user3222494

Reputation: 1

Multiple file uploading php with variable

I have some issues trying to upload multiple files from the same page in PHP.

This is my set up:

<input type='file' name='file1'></input>
<input type='file' name='file2'></input>
<input type='file' name='file3'></input>
<input type='file' name='file4'></input>

What i need is the fileX for my sql query so i can connect it to that input.

Ive tried looping in this case

for(x=1, x<=4, x++){
   if($_FILES['file'.x][error] == 0){
       upload 
   }
}

when i upload one file the loop ends ?

Anyone ?

Thanks

Upvotes: 0

Views: 78

Answers (2)

ventsi.slav
ventsi.slav

Reputation: 332

Just put [] at the end of the names. Like

<input type='file' name='file[]'></input>

Multiple array file[][your_id];

Upvotes: 0

Bilal
Bilal

Reputation: 2673

if(!empty($_FILES) {
    foreach($_FILES as $value)  
           // stuff to upload 
           // stuff to save in db
       }
    }
}

Links

Upvotes: 2

Related Questions