Upload file using array for files

Reply

Join Date: Mar 2008
Posts: 7
Reputation: dpatz is an unknown quantity at this point 
Solved Threads: 0
dpatz dpatz is offline Offline
Newbie Poster

Upload file using array for files

 
0
  #1
23 Days Ago
Hi,

I am reading in a bunch of files to upload but they are in an array:

  1. <input id="tab1file0" class="tab1Files files" type="file" name="tab1file[]" />
  2. <input id="tab1file1" class="tab1Files files" type="file" name="tab1file[]" />

To upload the files I call a function uploadFile() which looks like this:

  1. function uploadFile($thefile) {
  2. $base_path = "files/";
  3. $target_path = $base_path . basename( $_FILES[$thefile]['name']);
  4. echo($_FILES[$thefile]['tmp_name']);
  5. if(move_uploaded_file($_FILES[$thefile]['tmp_name'], $target_path)) {
  6. echo "The file ". basename( $_FILES[$thefile]['name'])." has been uploaded <br>";
  7. } else{
  8. echo "There was an error uploading the file".basename( $_FILES[$thefile]['name']).", please try again!<br>";
  9. }
  10. }

The only problem is when I get the files from the form, they are in an array and I can't seem to point the correct string to the upload file function.

Thanks!
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 539
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 63
network18 network18 is offline Offline
Posting Pro
 
0
  #2
22 Days Ago
Originally Posted by dpatz View Post
Hi,

I am reading in a bunch of files to upload but they are in an array:

  1. <input id="tab1file0" class="tab1Files files" type="file" name="tab1file[]" />
  2. <input id="tab1file1" class="tab1Files files" type="file" name="tab1file[]" />

To upload the files I call a function uploadFile() which looks like this:

  1. function uploadFile($thefile) {
  2. $base_path = "files/";
  3. $target_path = $base_path . basename( $_FILES[$thefile]['name']);
  4. echo($_FILES[$thefile]['tmp_name']);
  5. if(move_uploaded_file($_FILES[$thefile]['tmp_name'], $target_path)) {
  6. echo "The file ". basename( $_FILES[$thefile]['name'])." has been uploaded <br>";
  7. } else{
  8. echo "There was an error uploading the file".basename( $_FILES[$thefile]['name']).", please try again!<br>";
  9. }
  10. }

The only problem is when I get the files from the form, they are in an array and I can't seem to point the correct string to the upload file function.

Thanks!
you are looking for method like below -
  1. extract($_POST);
  2.  
  3. foreach($tab1file as $key=>$value)
  4. {
  5. //call your function here
  6. }
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Reply

Tags
array, files, php, upload

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC