5

I know this may sound relatively basic question, but still wanted to ask. I need to upload two files at once by creating two file input in my form one for each file. Until now I have used a basic script for testing to upload a single file.

I also found some examples how to upload muliple files, but in my case I am having two upload fields and I want the user to upload the two files. Once uploaded I wanted to save it onmy webserver. Any simple example would be of good help.

Thanks

0

2 Answers 2

2

It's simply just a case of changing the variable names and doing everything twice.

HTML:

<input type="file" name="filea" />
<input type="file" name="fileb" />

PHP:

$filea = $_FILES['filea'];
$fileb = $_FILES['fileb'];
move_uploaded_file($filea['tmp_name'], '/path/to/your/destination/'.$filea['name']);

Can you carry on from there?

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

3 Comments

Hi Grim, thanks man for the quick answer, I was trying it with using arrays, you saved my day.
Hi Grim, just a follow up, I can sucessfully upload .txt, .odt, excel files and so, but when I try to upload .pdf files even if it is of small size like 60KB, it is not uploading. Any idea
You'll have to post your code, as there's no reason for that to be the case. You should probably make it a new question, too.
0

Extrac data from $_FILES array

$file_1 = $_FILES['file1']['name']; $file_2 = $_FILES['file2']['name']; move_uploaded_file($_FILES['file1']['tmp_name'], 'pathproc/'.$file_1); move_uploaded_file($_FILES['file2']['tmp_name'], 'pathproc/'.$file_2);

1 Comment

Welcome to SO. It is always better to have an explanations in your answers, even a little one.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.