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>";
   }
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.