php multiple file upload

hattiesnake

New Member
I have a script I'm working out to upload up to 10 files at once. I have 10 seperate inputs in my html:\[code\] <?php for($i=0;$i<10;++$i) { $num = $i+1; echo ' <span>'.$num.'</span><input type="file" name="photo'.$i.'" /> '; } ?>\[/code\]And then I have my uploader which I have used before--in a slightly different form--but can't get to work now:\[code\]$path = "../path/to/folder/";for($i = 0; $i < 20; $i++){ $fileName = "photo". "$i"; $filePath = "$path". "photo$i.jpg"; if (!empty($_FILES['$fileName']['tmp_name'][$i])) { if (!copy($_FILES['$fileName']['tmp_name'][$i], $filePath)) { echo "failed to save '.$filePath.'"; } chmod($filePath, 0644); } }\[/code\]In a working version of this script I cut the for loop and just numbered each upload individually (I had this piece of code without the loop 10 times each with its own number). That worked great but it's really pretty ugly to look at a piece of code like that. Any ideas how to make this work?UPDATED:Still not having any luck I appreciate all the help. I think my problem lies in that the $_FILES arrays aren't being populated properly edits as follows:changed HTML to: \[code\] <?php for($i=0;$i<10;++$i) { $num = $i+1; echo ' <span>'.$num.'</span><input type="file" name="photo[]" /> '; } ?>\[/code\]and the uploader script to:\[code\]$path = "../path/to/folder/";for($i = 0; $i < 20; $i++){ $fileName = "photo". "$i"; $filePath = "$path$fileName.jpg"; if (!empty($_FILES["photo"]["tmp_name"][$i])) { if (!copy($_FILES["photo"]["tmp_name"][$i], $filePath)) { echo "failed to save '.$filePath.'"; } chmod($filePath, 0644); } }\[/code\]
 
Back
Top