Image upload not working.

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.";
		 }
	 }
 }

You’re “unable to upload the image through”? I see lots of error checking in the script, do you see any of those errors when trying to upload the image? Or do you see something else?

Nope, I directly see “Sorry, there was an error uploading your file.”
So there is something wrong on the server side…

@ckhawand said:
Nope, I directly see “Sorry, there was an error uploading your file.”
So there is something wrong on the server side…

It’s a server side script, so yes, it’s probably something server side.

Judging by the stage where that error could occur, I’d say the issue is that your script is unable to move the image to the target directory.

Your target directory is set to /images/. However, note that any file directory is relative to the root of your account, not of your website. And PHP can’t access files outside the website directory so it cannot upload the image to the target directory.

You could change the image path to be an absolute path within your website (using /htdocs/images/ would probably work if the domain is your primary account domain) or you could use a relative path (like images/, so without the first slash).

Okay, I’m going to try…