How can I upload files with PHP?

Error Message

no error message.

Other Information

I cant upload files. I have set chmod 777 to my tmp folder but it still fails. Why?
This is my index.php code:

<!doctype html>
<html lang="en">

    <form action="upload.php" method="post" enctype="multipart/form-data">
      Select file to upload:
      <input type="file" name="fileToUpload" id="fileToUpload">
      <input type="submit" value="Upload Image" name="submit">


$target_dir = "tmp/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
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;

I don’t see any code that actually uploads the image…


Thank you very much for your fast response :slight_smile:
I have added the missing code, now it works

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.