×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Coding

How does a multiple file upload work? by dpk136
Posted: 9 Feb 04 (Edited 10 Feb 04)

A lot of times, people want to have a form that has multiple uploads.  meaning that they want to have the user upload more than one file at a time.  i found that the way below is the easiest way to do this.  it just uses a simple "For" loop in php.  I have included some comments in the code below to explain what each step is doing.  


<?php
  $numoffile = 5; //number of files to upload
  //this is the directory you would like the files to go into
  // Fix path of your file to be uploaded, don't forget to CHMOD 777 to this folder

  $file_dir  = "/var/www/uploaded";   
  if ($_POST)
  {
    //if it is a post, loop through the $numoffile
    for ($i=0;$i<$numoffile;$i++) {
      if (trim($_FILES['myfiles']['name'][$i])!="") {
        //creates the new file name with trimmed spaces
        $newfile = $file_dir.$_FILES['myfiles']['name'][$i];
        //moves uploaded file from the tmp directory to the new directory with the file name
        move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newfile);
        $j++;
      }
    }
  }
  if (isset($j)&&$j>0)
  {
    echo ("Your file(s) has been uploaded.<br>");
  }
    echo ("<form method='post' enctype='multipart/form-data'>");
  for($i=0;$i<$numoffile;$i++) {
    echo ("<input type='file' name='myfiles[]' size='30'><br>");
  }
  echo ("<input type='submit' name='action' value='Upload'>");
  echo ("</form>");
?>

Back to PHP FAQ Index
Back to PHP Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close