I'm trying to create part of a form that uploads 5 images. At the moment I'm just trying to fix the validation of the images. Up to 5 images can be uploaded, the form contains 5 input fields for these (I know you can upload multiple files in one input but the design is designed like this, not my choice).
So firstly I check to see if the image checkbox has been checked (this runs fine) and then basically I try and check to see if there is an image uploaded, and then for each one with an image I try and run some basic validation (file size & type).
$imagesArray = array("order-desc-img", "order-desc-img-1","order-desc-img-2",
"order-desc-img-3", "order-desc-img-4"); //names of the file inputs
if (isset($_POST['images'])){ //check checkbox
$imagesQuantity = 1; //update variable to show it has been checked
foreach ($imagesArray as $image) { //loop through each item in array
$image_target_dir = "../uploads/images/";
$image_name = basename($_FILES[$image]["name"]);
$image_target_file = $image_target_dir . date('m-d-Y_hia') . '_' . $image_name;
if ($image_name != ''){ //if no name from file input
$imageFileType = pathinfo($image_target_file,PATHINFO_EXTENSION);
if ($_FILES[$image]["size"] > 5000000000) {
$errors++;
};//place holder file size check
if($imageFileType != "jpg" && $imageFileType != "jpeg" && $imageFileType != "png") {
$errors++;
};//placeholder file type check
}
}
};
However if I only try to upload one image the validation fails. If I try to upload all 5 I'm not sure what happens, it just stops on the validation page and never reaches the header for failing or successing. I'm not so great with debugging so I'm not sure how to figure out what I'm doing wrong. Am I going about it the wrong way?
Any help would be appreciated.