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

hakre
  • 193,403
  • 52
  • 435
  • 836
125369
  • 3,547
  • 20
  • 52
  • 70

2 Answers2

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?

Grim...
  • 16,518
  • 7
  • 45
  • 61
  • 1
    Hi Grim, thanks man for the quick answer, I was trying it with using arrays, you saved my day. – 125369 Feb 15 '12 at 10:05
  • 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 – 125369 Feb 15 '12 at 10:23
  • 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. – Grim... Feb 15 '12 at 10:24
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
    Welcome to SO. It is always better to have an explanations in your answers, even a little one. – endo64 Dec 12 '20 at 15:50