Hey alll,
I'm new to managing file uploads. I have a single file upload script working flawlessly however when I try to create a form that allows multiple files (in this case images) to be uploaded I get an error: Unable to upload: Array.
Here's my Form
<html>
<head>
<title>Test Upload</title>
</head>
<body bgcolor="#ffffff">
<form enctype="multipart/form-data" action="uploadFiles.php" method="post" name="upload">
<table border="0" cellspacing="0" cellpadding="2" width="350">
<tr>
<td valign="middle" width="350" colspan="2">
<b>Upload a File!</b>
</td>
</tr>
<tr>
<td valign="middle" width="50">
<b>File:</b>
</td>
<td valign="middle" width="300">
<input type="file" name="pictures[]">
</td>
</tr>
<tr>
<tr>
<td valign="middle" width="50">
<b>File:</b>
</td>
<td valign="middle" width="300">
<input type="file" name="pictures[]">
</td>
</tr>
<td valign="middle" width="50">
</td>
<td valign="middle" width="300">
<input type="submit" name="submit" value="Upload">
</td>
</tr>
</table>
</form>
</body>
</html>
And here's my script
<?
$target_path = "uploads/";
foreach ($_FILES['pictures']['error'] as $key => $error) {
if($error == UPLOAD_ERR_OK){
$tmp_name = $_FILES['pictures']['tmp_name'];
$name = $_FILES['pictures']['name'];
if(!move_uploaded_file($tmp_name, "$target_path$name")){
echo "Unable to upload: ".$name.".<br />";
}else{
echo "File: ".$name." uploaded successfully.<br />";
}
}
}
?>
Any and all help is greatly appreciated. Thanks!