To Store the images from database and show home page
Coding:-
config.php
<?php
$con= new mysqli("localhost","root","","function");
if($con->connect_error)
{
echo $con->connect_error;
die("sorry connected failed");
}
else
{
//echo "data connected successfully";
}
?>
Index.php
<!DOCTYPE html>
<html>
<head>
<title>To Store the images from database
</title>
</head>
<body>
<h1> Welcome to muthu images uploads</h1>
<form method="post" enctype="multipart/form-data">
<input type="file" name="image">
<input type="submit" name="submit" value="save">
</form>
<?php
if(isset($_POST["submit"]))
{
if(getimagesize($_FILES['image']['tmp_name'])==false)
{
echo 'please the select the images';
}
else
{
$image=$_FILES['image']['tmp_name'];
$name=$_FILES['image']['name'];
$image=file_get_contents($image);
$image=base64_encode($image);
$sql="INSERT INTO image(name,image)VALUES('$name','$image')";
if($con->query($sql))
{
echo "image stored";
}
else
{
echo "error";
}
}
}
else
{
echo "Please select image to save";
echo $con;
}
echo "<br>";
$sql="SELECT * FROM image";
$result=$con->query($sql);
if($result->num_rows>0)
{
while($row=$result->fetch_assoc())
{
echo "<img width='300px'
height='300px' src='data:image;base64,{$row["image"]}'
alt='img'>";
echo "<br><hr>";
}
}
else
{
echo "No images to Stored";
}
?>
</body>
</html>
config.php
<?php
$con= new mysqli("localhost","root","","function");
if($con->connect_error)
{
echo $con->connect_error;
die("sorry connected failed");
}
else
{
//echo "data connected successfully";
}
?>
Index.php
<!DOCTYPE html>
<html>
<head>
<title>To Store the images from database
</title>
</head>
<body>
<h1> Welcome to muthu images uploads</h1>
<form method="post" enctype="multipart/form-data">
<input type="file" name="image">
<input type="submit" name="submit" value="save">
</form>
<?php
if(isset($_POST["submit"]))
{
if(getimagesize($_FILES['image']['tmp_name'])==false)
{
echo 'please the select the images';
}
else
{
$image=$_FILES['image']['tmp_name'];
$name=$_FILES['image']['name'];
$image=file_get_contents($image);
$image=base64_encode($image);
$sql="INSERT INTO image(name,image)VALUES('$name','$image')";
if($con->query($sql))
{
echo "image stored";
}
else
{
echo "error";
}
}
}
else
{
echo "Please select image to save";
echo $con;
}
echo "<br>";
$sql="SELECT * FROM image";
$result=$con->query($sql);
if($result->num_rows>0)
{
while($row=$result->fetch_assoc())
{
echo "<img width='300px'
height='300px' src='data:image;base64,{$row["image"]}'
alt='img'>";
echo "<br><hr>";
}
}
else
{
echo "No images to Stored";
}
?>
</body>
</html>
Comments
Post a Comment