<html>
<head>
<title>Upload</title>
</head>
<body>
<form action="index.php" method="POST" enctype="multipart/form-data">
File:
<input type="file" name="image" accept="image/*"><!--We will allow any type of images such as jpg or png or etc-->
<input type="submit" name="submit" value="Upload">
</form>
<?php
error_reporting(E_ALL ^ E_NOTICE);
//connect to database
mysql_connect("localhost","root","pwd") or die (mysql_error());
mysql_select_db("upload") or die (mysql_error());
if(isset($_POST['submit']))
{
//file properties
$file=$_FILES['image']['tmp_name'];
$image_name=mysql_real_escape_string($_FILES['image']['name']);
$image=mysql_real_escape_string(file_get_contents($file));
$image_size=getimagesize($file);
if($image_size==FALSE)
{
echo "That is not an image";
}
else
{
$insert=mysql_query("INSERT INTO store (name,image) VALUES ('$image_name','$image')");
if($insert)
{
echo "OK!";
$lastid=mysql_insert_id();
echo "Image<p/>Your image: <img src=get.php?id=$lastid>";
}
else
{
echo "PROBLEM!";
}
}
}
else
{
echo "That is not an image!";
}
?>
</body>
</html>