-4

HTML file:

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

PHP file(upload.php):

<?php
$uploaddir = 'new/';
$uploadfile = $uploaddir . 
basename($_FILES['userfile']['name']);

echo "<p>";

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded. $uploadfile \n";
} else {
echo "Upload failed";
}
echo "</p>";
echo '<pre>';
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?> 

Im useing this php code. But after uploading it shows that it failed. Why it's failing. Here is an demo test, http://labrat.herobo.com/g.html

1 Answers1

2

No input tag is associated with userfile.

Please change

$_FILES['userfile'] to $_FILES['fileToUpload']

OR

<input type="file" name="fileToUpload" id="fileToUpload"> to <input type="file" name="userfile" id="fileToUpload">
Muhammad Hassaan
  • 7,296
  • 6
  • 30
  • 50
Happy Coding
  • 2,517
  • 1
  • 13
  • 24