0

This is the error appearing on browser screen.

Notice: Undefined index: name in C:\wamp64\www\roomdhundhoo\roomdhundho\owner\test.php on line 3

My HTML Code.

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Image upload</title>
  </head>
  <body>
    <form class="" action="test.php" method="post" enctype="multipart/form-data">
      <input type="file" name="pic" id="pic" value="">
      <input type="submit" name="submit" value="Get image">
    </form>
  </body>
</html>

When i am trying to upload file using $_FILES['pic']['name'] function, it is showing that 'name' index is not defined.

My PHP Code.

<?php
  if(isset($_POST["submit"])) {
    $file_name=$_FILES["pic"]["name"];
  }
?>

When i tried this code:-

<?php
  if(isset($_POST["submit"])) {
     $file_name = basename($_FILES['pic']['name']);
  }
?>

Same error is coming.

My code is successfully displaying file name directly. This means that PHP file is recognising that file has been submitted.

CODE

<?php
  if(isset($_POST["submit"])) {
     $file_name = $_POST['pic'];
     echo $file_name;
  }
?>

OUTPUT

Screenshot (29).png

This is the file name, which i uploaded.

Rahul
  • 310
  • 2
  • 13
  • Does `var_dump($_FILES);` give you all correct details? – nice_dev Feb 23 '20 at 13:52
  • You have to check `$_FILE` not just `$_POST` since you might be submitting the form without uploading a file. – ROOT Feb 23 '20 at 14:21
  • As i said, i am just testing my code, so i properly upload the file. This code `` is properly displaying the file name. That means file has been selected. – Rahul Feb 23 '20 at 18:22
  • When i am checking `$_FILE` then it is returning false even i upload the file. – Rahul Feb 23 '20 at 18:35

0 Answers0