0

There are many similar questions that have been answered (I see every question related to this is marked as duplicate) but I can't find anything that solves this. I am not good at PHP, I'm just now getting started. Either way, I get "Notice: Undefined index: file in Applications/XAMPP/xamppfiles/htdocs/upload_file.php on line 12".

I got this code from someone else on here who had a problem I previously had. Someone in the comments fixed his error so I copied his code and then did the same. But now my code doesn't work, what should I do?

Code

  <?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
//removed comment
//removed comment
$allowedExts = array("mp4", "mpg", "mov", "flv", "avi");
$temp = explode(".", $_FILES["file"]["name"]);
print_r($_FILES["file"]["type"]);
$extension = end($temp);
if (($_FILES["file"]["size"] < 200000)) {
  if ($_FILES["file"]["error"] > 0) {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
  } else {
    echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
    if (file_exists("uploads/" . $_FILES["file"]["name"])) {
      echo $_FILES["file"]["name"] . " already exists. ";
    } else {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "uploads/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "uploads/" . $_FILES["file"]["name"];
    }
  }
} else {
  echo "Invalid file";
}
?>

EDIT:

I was asked for the html form, so here ya' go.

<!DOCTYPE html>
<html>
<body>

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

</body>
</html>

1 Answers1

-1

I think

<input type="file" name="fileToUpload" id="fileToUpload"> 

should be

<input type="file" name="file" id="fileToUpload">
Matt McManis
  • 4,475
  • 5
  • 38
  • 93
  • Thanks! Don't know who downvoted this but it fixed the problem for me. I get another error but I can fix that one. :D – Knot Snappy Apr 08 '17 at 15:31