0

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

2 Answers2

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

Links

Community
  • 1
  • 1
Bilal
  • 2,645
  • 3
  • 28
  • 40
  • Okey , cant really get my head around it but ill try. Looks like something im after ! Thanks – user3222494 Jan 22 '14 at 08:14
  • You can use methods like `print_r()`, `var_dump()` to track values you receive at any step, debug your code. Don't forget to put a `die()` after these methods if you want to stop your script execution and see what you are receiving actually. – Bilal Jan 22 '14 at 08:22
0

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

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

Multiple array file[][your_id];

ventsi.slav
  • 334
  • 1
  • 4
  • 14