2

I have the following html form:

<form method="post" enctype="multipart/form-data">
   File: <input type="file" name="file"><br>
   Name: <input type="text" name="file_name"><br>
   <input type="submit" name="action" value="Upload">
</form>

But the file never gets uploaded. The text field is just there as debug code.

The following php code:

  <?php
  echo "<pre>";
  print_r($_POST);
  echo "</pre>";
  ?>

Gives the following output when I fill all the forms values:

Array (

[file_name] => abc

[action] => Upload )

And I'm running a php server as follows:

php -nS localhost:8000 -t .

Am I doing anything wrong here? It's all running locally and the file I'm uploading is less than 10 bytes long.

Community
  • 1
  • 1
Toadjk
  • 23
  • 3
  • 1
    Try getting the file with $_FILES – Patrick Sep 14 '17 at 14:34
  • The file information should be located in the [$_FILES superglobal](http://php.net/manual/en/reserved.variables.files.php) – aynber Sep 14 '17 at 14:34
  • PHP won't upload the file for you. You have to tell it to upload the file. Also, grab it with $_FILES to be able to upload it. – tdoggy Sep 14 '17 at 14:37
  • @tdoggy I had code to upload before, this was only debug stuff. The problem was with _POST -> _FILES. – Toadjk Sep 14 '17 at 15:50

2 Answers2

0

You will find your data about the uploaded file in this variable: $_FILES["file"] and not in the $_POST variable.

Matei Rogoz
  • 131
  • 4
0

First, ensure that PHP is configured to allow file uploads.

In your "php.ini" file, search for the file_uploads directive, and set it to On:

file_uploads = On

Suhag Lapani
  • 655
  • 10
  • 18