[Solved] How to upload a file to a server then record it in a MySQL database? [closed]


Uploaded file are not in the $_POST but in $_FILES which in an array.

There is a sample to simply upload a file and retreive information on it.

<html>
<body>

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>

</body>
</html>

And

<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br>";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br>";
  echo "Type: " . $_FILES["file"]["type"] . "<br>";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
  }
?> 

move_uploaded_file php directive is the way to move the temporary uploaded file to the final directory and there are many code to put the name in MySQL.

I let you search 😉

solved How to upload a file to a server then record it in a MySQL database? [closed]