×
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

Simple Multiple Upload Script (Both HTML and PHP) by kb244
Posted: 20 Feb 05

There are two parts to this, and I'm going to keep the code very simple, the path in the php portion of it is geared at a windows machine, just simply change this path for what it would be on your box or web hosting provider. I made this simple script up when helping a friend figure out how to do multiple uploads to premade gallery folders so he could upload pictures to his site.

The HTML Portion

CODE

<form enctype="multipart/form-data" method="post" action="uploader.php">
    <select name="destination">
        <option value="gallery_1">Gallery One</option>
        <option value="gallery_2">Gallery Two</option>
        <option value="gallery_3">Gallery Three</option>
    </select><br>
    <input name="photos[]" type="file"><br>
    <input name="photos[]" type="file"><br>
    <input name="photos[]" type="file"><br>
    <input name="photos[]" type="file"><br>
    <input type="submit">
</form>

The PHP Portion

CODE

<?
 $file = $_FILES['photos'];
  
 for($i = 0; $i < sizeof($file); $i++)
     {
         echo "inside of loop<BR>";
         if($file['error'][$i] == 0)
         {
             $newfile = "C:\\Path\\To\\Destination\\".$_POST['destination']."\\".$_FILES['photos']['name'][$i];
             
             move_uploaded_file($_FILES['photos']['tmp_name'][$i], $newfile);
             
             echo "Moved : ".$newfile."<BR>";
         }
         else
             echo $file['error'][$i]."<BR>";
     }
?>

If on a windows box, make sure when yer doing your paths such as above, that there are double backslash since backslash is an escape character, on a *nix box you are more likely to be using forward slash for the path so this isnt an issue on a *nix box.

There you have it a very simple way to upload multiple files to premade destinations.

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