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
  • What is the code of "upload" and how does your complete form look like? Commented Jan 22, 2014 at 7:55
  • And do a var_dump($_FILES) and post the result. Commented Jan 22, 2014 at 8:08

2 Answers 2

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

Links

Sign up to request clarification or add additional context in comments.

2 Comments

Okey , cant really get my head around it but ill try. Looks like something im after ! Thanks
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.
0

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

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

Multiple array file[][your_id];

3 Comments

Yeah i know, but what if my file_id(x) starts is 8 - 12, <input type='file' name='file8'></input> <input type='file' name='file9'></input>... Then i use the file_id for query.
I want to use the number in "file1-X" as variable in insert to sql db
Then use multiple array file[][your_id]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.