I am trying to adjust my upload code to handle multiple uploads at the same time, I have searched and found all kinds of code that says to wrap my current upload scrypt inside of it and just change my file system to an array but every time I do I get an error so here is the code I am working with:
session_start();
error_reporting(E_ALL);
//foreach($_FILES['file'] AS $file)
//{
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
if (file_exists("pics/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"pics/" . $_FILES["file"]["name"]);
$path = $_FILES["file"]["name"];
$sql = "INSERT INTO uploads (ref_id, name) VALUES('$_POST[refID]', '$path')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}else
{
?>
<script type="text/javascript">
alert("Inventory successfully updated, Thank You");
document.location.href="picUploads.php";
</script>
<?php
}
}
}
}else
{
echo "Invalid file";
}
//}
the foreach statment is commented out because I wanted to check and make sure again that the code worked for a single upload which it does. here is the form for a single upload
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Photo Upload</title>
</head>
<body onUnload="window.addEventListener("unload", invalidateBackCache, true)">
<center><h1>UPLOAD PICTURES</h1></center>
<form action="upload.php" method="post"
enctype="multipart/form-data">
<input type="hidden" name="refID" value=<?php echo $_POST['refID']; ?> /><br />
<label for="file">Pictures to be uploaded:</label><br />
<input name="file" type="file" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
when I change <input name="file" type="file" />
to <input name="file[]" type="file" />
adding another couple of input fields and wrapping my upload script in the foreach code I get an error that says there is an error on line 10 of my upload.php which is this line $extension = end(explode(".", $_FILES["file"]["name"]));
the error says that explode expects the forst paramiter to be an array and end expects the second paramiter to be a string, I understand what the error is telling me but I am not sure how to adjust the code to give it what it is wanting.