First of all you need to add the enctype
attribute to your HTML form. Like this:
<form action="page.php" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<input type="file" name="photo" id="photo" />
<input type="submit" value="Upload" />
</form>
Next, when this will be sent on the next page use the $_FILES
global array instead of the $_POST
array to retrieve the image.
<?php
move_uploaded_file( $_FILES['photo']['tmp_name'], "/var/www/image.jpg" );
echo("<img src='image.jpg'");
?>
All text data will be sent using $_POST
but the file will be transferred using $_FILES
.
Edit: If you further want to insert this uploaded data in the table (although this is never recommended and is a huge performance loss)
$image = file_get_contents( "/var/www/image.jpg" );
$image = addslashes( $image );
...
$sql = "INSERT INTO pictures(image) VALUES('" . $image . "')";
//remaining MySQL and PHP code
Note: Here I am considering /var/www
as my web folder which is configured as default localhost on Linux machines.