0

Form to upload files:

   <form action="<?Php echo $_SERVER["PHP_SELF"];?>"method="post"enctype="multipart/form-data">
   <input type="file"name="uf[]">
  <input type="file"name="uf[]">
 <input type="file"name="uf[]">
 <input type="submit"value="upload"name="ok">
 </form>

PHP script to receive files:

  <?php
  if(!isset($_POST["ok"]))
   {echo "Sorry ,could not upload!";}
 else
 {     $f1=$_FILES["uf"]["name"][0];
   $f2=$_FILES["uf"]["name"][1];        $f3=$_FILES["uf"]["name"][2];
     $path="path/";$filea=$path.$f1;
   $fileb=$path.$f2;$filec=$path.$f3;
  move_uploaded_file($_FILES["uf"][0]["tmp_name"],$filea);
 move_uploaded_file($_FILES["uf"][1]["tmp_name"],$fileb);
 move_uploaded_file($_FILES["uf"][0]["tmp_name"],$filec);}
  ?>

The files are not getting saved and I am getting a user defined error

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • You ain't doing proper error checking. The PHP manual has a whole section dedicated to file uploads which contains all the information (the answer you accepted isn't of much use for the matter), it's here: [Handling File Uploads](http://php.net/file_upload). For the undefined index errors you don't recognize because you've made yourself needlessly blind to them, see [How to get useful error messages in PHP?](http://stackoverflow.com/q/845021/367456) on how to show them. – hakre Mar 29 '15 at 07:44

1 Answers1

1

In your case if the form is not send you print `"Sorry ,could not upload!" your error was in this lines:

 move_uploaded_file($_FILES["uf"][0]["tmp_name"],$filea);
 move_uploaded_file($_FILES["uf"][1]["tmp_name"],$fileb);
 move_uploaded_file($_FILES["uf"][0]["tmp_name"],$filec);

Try with this:

  <?php
  if(!isset($_POST["ok"]))
   {echo "Sorry ,could not upload!";}
 else
 { 
   $f1=$_FILES["uf"]["name"][0];
   $f2=$_FILES["uf"]["name"][1];        
   $f3=$_FILES["uf"]["name"][2];

   $path="path/";
   $filea=$path.$f1;
   $fileb=$path.$f2;
   $filec=$path.$f3;

  move_uploaded_file($_FILES["uf"]["tmp_name"][0],$filea);
  move_uploaded_file($_FILES["uf"]["tmp_name"][1],$fileb);
  move_uploaded_file($_FILES["uf"]["tmp_name"][2],$filec);

}


  ?>
Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63