Jump to content

PHP Tutorial - File Upload


Maz

Recommended Posts

Hi there,

I was following your tutorial on PHP and found a little mistake in coding of "File Upload". When I ran the code I was seeing the errors on top of the form after page load. I tried and put the next IF's inside the first IF and it did worked. Just wanted to inform you about this code and hope to fix it for others in the future. Thanks for the great website and wish you all the best.

Cheers.

 

if(isset($_POST["submit"])) {
  $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  if($check !== false) {
    echo "File is an image - " . $check["mime"] . ".";
    $uploadOk = 1;
  } else {
    echo "File is not an image.";
    $uploadOk = 0;
  }
}

// Check if file already exists
if (file_exists($target_file)) {
  echo "Sorry, file already exists.";
  $uploadOk = 0;
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...