Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Multiple Upload Script (Both HTML and PHP)

Coding

Simple Multiple Upload Script (Both HTML and PHP)

by  Karl Blessing  Posted    (Edited  )
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.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top