Jump to content

handle multiple file upload and processing each?


acctman

Recommended Posts

Hi can someone assist me with adding a second upload that grabs all files from within a directory.

 

1. user select .csv file (coding down for that)

2. user select folder with .docx files in side (this folder will only have docx files)

3. on submit .csv and all .docx files are upload to /temp_docx/ folder

4. the .csv has a matching docx_id that relates to the .docx file name (ex file 1.docx == docx_id = 1 in the csv file) so every time an insert is done a move_file happens and 1.docx would be moved to /docx_files/

5. and if there is ever an error or no match at the end output all errors.

 

I think the part where i'm stuck and confused the most is handling the second upload where all docx files in the folder are upload and looped through moving and inserting

 

<?php
if(isset($_POST['submit']))
   {
     $filename = file_get_contents($_FILES['uploadedfile']['tmp_name']);
     $handle = fopen("$filename", "r");
     while (($data = fgetcsv($handle, 100000, ",")) !== FALSE)
     {
    
       $import="INSERT into kmmb_member1(docx_id,no_ahli,no_pin,nama,no_ic_baru,no_ic_lama) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]')";
       mysql_query($import) or die(mysql_error());
     }
     fclose($handle);
     print "Import done";
   }
   else
   {

      print "<form action='import.php' method='post'>";
      print "Type file name to import:<br />";
      print "Select csv file: <input name='uploadedfile' type='file' /><br />";
      print "<input type='submit' name='submit' value='submit' /></form>";
   }
?>

i'm assuming a directory upload can't be done with a php file upload and flash would be needed. so can anyone show me how this would be done with a single php file upload and I can look into the flash part after i have everything working correctly

 

yes only one upload is needed. lets say that the files are already on the server. once the .csv file is in $data[0] is used to go to /temp_docx/ folder and look for the file $data[0] that matches (ex. $data[0] = 1 then look for 1.docx and move it to /docx_files/ and do the insert into the database.

 

i just need help with the part where $data[0] is used to check the directory on the server for the corresponding file and then the move

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.