Hello,
I am trying to prevent my form, from submitting if the file is not an image type file but i keep failing, the array that i am using keeps displaying regardless of the files type.
Any help would be grateful.
<?php
$Manufacturer = $_POST['Manufacturer'];
$Brand = $_POST['Brand'];
$Model = $_POST['Model'];
$Type = $_POST['Type'];
$Wheel = $_POST['Wheels'];
$Colour = $_POST['Colour'];
$Number = $_POST['Gears'];
$Brake = $_POST['Brakes'];
$Suspension = $_POST['Suspension'];
$Gender = $_POST['Gender'];
$Age = $_POST['Ageof'];
$image = $_FILES["images"]["name"];
$Additional = $_POST['Additional'];
include "../include/config.php";
$upload_folder = "./uploads/";
$result=mysqli_query($connection,"SELECT * FROM `Bike` WHERE manufacturer='$Manufacturer'");
//$file="./uploads/".$_FILES["images"]["name"];
//$image = addslashes(file_get_contents($_FILES . '../BikeRegistrationDAO.php'));
if($row=mysqli_num_rows($result) > 0){
echo "This Bicycle's Manufacturer, Is already registered.";
return;
}
$allowed = array("jpg", "jpeg", "png", "gif");
if (array($allowed !== "jpg", "jpeg", "png", "gif"))
{
die("Not a gif/jpeg/png");
}
foreach($_FILES["images"]["name"] as $key => $file_name)
{
$tmp_name = $_FILES["images"]["tmp_name"][$key];
if(file_exists ($upload_folder.$file_name))
{
echo "The file ". $file_name . " already exists". "</br>";
}else{
move_uploaded_file($tmp_name, $upload_folder.$file_name." MPN: ".$Manufacturer); // uploads the image file name to the folder with the bikes MPN number next to it !
echo "The file " . $file_name . " has successfully uploaded". "</br>";
}
}
$sql = "INSERT INTO Bike (Manufacturer, Brand, Model, Type, Wheel, Colour, Number, Brake, Suspension, Gender, Age, image, Additional) VALUES ('$Manufacturer', '$Brand', '$Model', '$Type', '$Wheel', '$Colour', '$Number', '$Brake', '$Suspension', '$Gender', '$Age', '$image', '$Additional')";
if(!mysqli_query($connection, $sql))
{
echo "Not Submited";
}else{
echo "Submitted Successfully"."</br>";
}
?>