Search code examples
phphtmlformswebserver

No file upload on php built-in web server


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.


Solution

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