Log in

View Full Version : Uploading Multiple Files



aarondressler
09-30-2006, 09:31 PM
Hi.. I found this script that allows you to upload multiple files. It only displays one upload form at a time, and thanks to javascript, starts a list of all the files you selected. THIS works fine... The only drawback to this cool script is that it formats the $_FILES data by naming each upload differently (the name property in the HTML file input is fixed for every upload box as "file_0", "file_1", "file_2" and so on...), instead of using the same name, and indexing the multiple files. Since I dont want to go through the other authors JavaScript, i've been trying to write my php to adjust accordingly.. What I have works just fine. It creates the customer's directory just fine, however it doesn't put anything inside of it, but it doesn't give me any errors on the move_uploaded_file, and it shows the files array in full when I print_r($_FILES)... what's going on here???

Heres my code:

$numFiles = $_GET['numFiles'];
$orderId = $vars['orderID'];
$destDir = "uploads/".$orderId;


mkdir($destDir, 0777);

for ($i=0; i<$numFiles; $i++) {
$file = "file_".$i;
$name = basename($_FILES[$file]['name']);
$location = $destDir.'/'.$name;
if (move_uploaded_file($_FILES[$file]['tmp_name'], $location)){
@chmod($location, 0775);
} else { die('Upload Failed. '.mysql_error());}
}
@chmod($destDir, 0775) or die('Error on chmod....');

#REST OF CODE...

aarondressler
10-01-2006, 06:02 PM
missing a $ infront of the i....