You are on page 1of 2

<?

php
ini_set('mysqli.connect_timeout',300);
ini_set('default_socket_timeout',300);
?>
<html>
<body>
<form method="post" enctype="multipart/form-data">
<br/>
<input type="file" name="image" />
<br/><br/>
<input type="submit" name="sumit" value="Upload" />
</form>
<?php
if(isset($_POST['sumit']))
{
if(getimagesize($_FILES['image']['tmp_name']) == FALSE)
{
echo "Please select an image.";
}
else
{
$image= addslashes($_FILES['image']['tmp_name']);
$name= addslashes($_FILES['image']['name']);
$image= file_get_contents($image);
$image= base64_encode($image);
saveimage($name,$image);
}
}
//displayimage();
function saveimage($name,$image)
{
$con=mysqli_connect("localhost","root","","test");
$qry="insert into images (name,image) values ('$name','$image')"
;
$result=mysqli_query($qry) or trigger_error("Query Failed! SQL:
$qry - Error: ".mysqli_error($con), E_USER_ERROR);
if($result)
{
echo "<br/>Image uploaded.";
}
else
{
echo "<br/>Image not uploaded.";
}
}
/*function displayimage()
{
$con=mysqli_connect("localhost","root","","test");
$qry="select * from images";
$result=mysqli_query($qry,$con);
$row=mysqli_num_rows($result);
while($row=mysqli_fetch_assoc($result))
{
echo '<img height="300" width="300" src="data:image;base64,'
.$row[2].' "> ';
}
mysqli_close($con);
}*/
?>
</body>

</html>

You might also like