So I grabbed an image upload code from w3schools.
Everything worked fine on other hosts, but here, I am unable to upload the image through , I have set the form to multiform.
Here’s the php code
if(isset($_POST['new'])){
$target_dir = "/image/";
$uploadOk = 1;
$info = getimagesize($_FILES['fileToUpload']['tmp_name']);
$imageFileType = $info['mime'];
$target_file = $target_dir . rand(1000000,9999999) . $imageFileType;
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
$uploadOk = 1;
} else {
$errMSG .= "File is not an image.";
$uploadOk = 0;
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 2000000) {
$errMSG .= "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "image/jpg" && $imageFileType != "image/png" && $imageFileType != "image/jpeg"
&& $imageFileType != "image/gif" ) {
$errMSG .= "Sorry, only JPG, JPEG, PNG & GIF files are allowed.".$imageFileType;
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
$errMSG .= "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
if(isset($_POST['status'])){
$status = '1';
}else{
$status = '0';
}
$image = $target_file;
$ename = $_POST['ename'];
$location = $_POST['loc'];
$query = mysqli_query($conn,"INSERT INTO `events` (name,user,views,checkins,status,location) values($ename,$id,'0','0','$status','$loc')");
header('Location: status.php?ref=new&success=1');
exit;
}else{
$errMSG = "Sorry, there was an error uploading your file.";
}
}
}