0

Here I have a basic html form with an choose file input and submit button. In my linked PHP page, I am trying to display the information of the file inside of an array in the browser, but am getting an undefined index error Undefined index: file on each of the two lines of code where my two variables are. Why am I getting this error?

My HTML

<!DOCTYPE html>
<html>
  <head>
    <title></title>
  </head>
  <body>
    <form action="upload.php" method="POST" enctype="mulitpart/form-data">
      <input type="file" name="file">
      <button type="submit" name="submit">UPLOAD</button>
    </form>
  </body>
</html>

My PHP code

  <?php

  if (isset($_POST['submit'])) {
    $file = $_FILES['file'];
    print_r($file);
    $fileName = $_FILES['file']['name'];
  }
Fins Up
  • 39
  • 1
  • 3
  • 13

2 Answers2

2

you spelt "multipart/form-data wrong"

Festus Yuma
  • 155
  • 1
  • 6
1

your enctype="mulitpart/form-data" must enctype="multipart/form-data"

and then on your upload.php

$nameFile = $_FILES['file']['name']; //for name of picture
    $sizeFile = $_FILES['file']['size']; // for size picture
    $error = $_FILES['file']['error']; // for error 
    $tmpName = $_FILES['file']['tmp_name']; // 

if you want to show it you must convert to array like

$data [
$nameFile, $sizeFile, $error, $tmpName
];

and show with print_r($data);

Tofan
  • 31
  • 2