Multiple File Uploads..
Posted: Sun Oct 23, 2005 11:58 pm
I don't want to be a bother, but I did a search on the subject, but nothing came up that could help me, so...
I have a page 'upload.php' which lets you select multiple files to upload to a directory of your choice (using a drop-down box) which goes to 'uploads2' so the php can do its thing.
Heres the form on the first page (10 fields):
And here's the PHP on the second page:
I have tried changing the directory in the move_uploaded_file functions to a ton of things, like full unix path, full url, with and without the leading slashes, etc. I know that the array is working and all that because it shows the right info when I have print_r($_FILES); in there. It isn't working though, I don't get any errors, the file isn't appearing in the directory, so I can only assume that's it, but I've tried so many different directory variations. Any help would be nice.
-Thanks
I have a page 'upload.php' which lets you select multiple files to upload to a directory of your choice (using a drop-down box) which goes to 'uploads2' so the php can do its thing.
Heres the form on the first page (10 fields):
Code: Select all
<form action="upload2.php" enctype="multipart/form-data" method="post">
<table align="center" cellpadding="0" cellspacing="0">
<tr><td align="left"><input type="file" name="file[]"></td><td align="left"><input type="file" name="file[]"></td></tr>
<tr><td align="left"><input type="file" name="file[]"></td><td align="left"><input type="file" name="file[]"></td></tr>
<tr><td align="left"><input type="file" name="file[]"></td><td align="left"><input type="file" name="file[]"></td></tr>
<tr><td align="left"><input type="file" name="file[]"></td><td align="left"><input type="file" name="file[]"></td></tr>
<tr><td align="left"><input type="file" name="file[]"></td><td align="left"><input type="file" name="file[]"></td></tr>
<tr><td align="center" colspan="2"><p class="text2">Choose a directory for these files to be placed in: <select name="directory"><option value="a">/<option value="b" selected>/images/<option value="c">/files/</select></p>
<tr><td align="center" colspan="2"><input type="submit" value="Upload"></td></tr>
</table>
</form>Code: Select all
$directory=$_POST['directory'];
if($directory=='a')$dir='http://www.paulleduc.com/';
if($directory=='b')$dir='http://www.paulleduc.com/images/';
if($directory=='c')$dir='http://www.paulleduc.com/files/';
foreach ($_FILES[$_POST['file']]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES[$_POST['file']]["tmp_name"][$key];
$name = $_FILES[$_POST['file']]["name"][$key];
if($directory=='a')move_uploaded_file($tmp_name, "/htdocs/$name");
if($directory=='b')move_uploaded_file($tmp_name, "/htdocs/images/$name");
if($directory=='c')move_uploaded_file($tmp_name, "/htdocs/files/$name");
}
}-Thanks