Hi everyone, I am new to PHP, and I am trying to upload 10 files with differnt input names. From reading forums and such, I came up with the following code, but it doesn't seem to be working. Can anyone tell me where I went wrong?
if (isset($_POST[submit])) {
$uploadArray= array();
$uploadArray[] = $_POST['image01'];
$uploadArray[] = $_POST['image02'];
$uploadArray[] = $_POST['image03'];
$uploadArray[] = $_POST['image04'];
$uploadArray[] = $_POST['image05'];
$uploadArray[] = $_POST['image06'];
$uploadArray[] = $_POST['image07'];
$uploadArray[] = $_POST['image08'];
$uploadArray[] = $_POST['image09'];
$uploadArray[] = $_POST['image10'];
foreach($uploadArray as $file) {
//This is the directory where images will be saved
$target = "orders/";
$target = $target . basename( $_FILES[$file]['name'] );
if (
(($_FILES[$file]["type"] == "image/gif")
|| ($_FILES[$file]["type"] == "image/jpg")
|| ($_FILES[$file]["type"] == "image/jpeg")
|| ($_FILES[$file]["type"] == "image/pjpeg"))
&& ($_FILES[$file]["size"] < 5000000)
)
{
if(move_uploaded_file($_FILES[$file]['tmp_name'], $target))
{
// redirect to upload success url
header('Location: ' . SUCCESS_URL);
die();
break;
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
else
{
echo "Invalid file";
}
}
}