1

I want to upload multiple files in a single submit button using PHP but its not working and i had tried upload a single file using php and it was working well so i thought that it would be good to just copy the same code for the second file to have two files uploaded but in vain.

i had tried this solution on SO but i had no success :solution1

solution2

solution3

 <form action="" method="post" target="frame" enctype = "multipart/form-data"> <div class="buttonsend"> <p>Entrez votre fichier.cfg :</p> <input type = "file" name = "cfg" /></br> <p>Entrez votre fichier.dat :</p> <input type = "file" name = "dat" /></br></br> <button id="send" type="submit" name="send">Générer</button> </div> </form> <?php if (isset($_POST['send'])) { $file_tmpcfg = $_FILES['cfg']['tmp_name']; $file_namecfg = $_FILES['cfg']['name']; move_uploaded_file($file_tmpcfg,"/home/imagesdcard/www/".$file_namecfg); $file_tmpdat = $_FILES['dat']['tmp_name']; $file_namedat = $_FILES['dat']['name']; move_uploaded_file($file_tmpdat,"/home/imagesdcard/www/".$file_namedat); } ?> 
6
  • What happens when try? Do you get an error? Does nothing happen? Commented Jul 17, 2019 at 9:52
  • What output do you get if you do a var_dump( $_FILES ); inside your if statement? Commented Jul 17, 2019 at 9:55
  • var_dump($_FILES) didn't output anything , is it normal ? maybe i have to set something on my php.ini Commented Jul 17, 2019 at 11:17
  • It should output something. The code seems fine. Which browser are you using? Commented Jul 17, 2019 at 11:27
  • im using firefox and lighttpd. Commented Jul 17, 2019 at 11:31

1 Answer 1

0

It is working fine. I printed uploaded files and it didnt show any error.

 <form action="" method="post" target="frame" enctype = "multipart/form-data"> <div class="buttonsend"> <p>Entrez votre fichier.cfg :</p> <input type = "file" name = "cfg" /></br> <p>Entrez votre fichier.dat :</p> <input type = "file" name = "dat" /></br></br> <button id="send" type="submit" name="send">Générer</button> </div> </form> <?php if (isset($_POST['send'])) { $uploaddir = '/var/www/html/'; $uploadfileCfg = $uploaddir . basename($_FILES['cfg']['name']); $uploadfileDat = $uploaddir . basename($_FILES['dat']['name']); echo "<p>"; if (move_uploaded_file($_FILES['cfg']['tmp_name'], $uploadfileCfg)) { echo "File cfg is valid, and was successfully uploaded.\n<br>"; }else{ echo "File cfg is invalid"; } if (move_uploaded_file($_FILES['dat']['tmp_name'], $uploadfileDat)) { echo "File dat is valid, and was successfully uploaded.\n<br>"; }else{ echo "File dat is invalid"; } echo "</p>"; echo '<pre>'; echo 'Here is some more debugging info:<br>'; print_r($_FILES); print "</pre>"; } ?> 

result:

File cfg is valid, and was successfully uploaded. File dat is valid, and was successfully uploaded. Here is some more debugging info: Array ( [cfg] => Array ( [name] => 102440.jpg [type] => image/jpeg [tmp_name] => /tmp/phpQdhjY0 [error] => 0 [size] => 72469 ) [dat] => Array ( [name] => 1plus1.pem [type] => application/x-x509-ca-cert [tmp_name] => /tmp/phpId9rW1 [error] => 0 [size] => 1692 ) ) 
Sign up to request clarification or add additional context in comments.

2 Comments

But when i tried to check in the path if the file is existed or not, i learned that the files uploaded wasn't there so i figured that something is wrong with my code.
might be but as you asked about uploading files issue, that is solved.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.