I am learning MYSQL and PHP. I want to upload the image and show the image by retrieving it from the database. Everything is good but I am not able to show the image. Please help me below is the code. Thanks in advance.
<!doctype html>
<html>
<head><title>Image Uploader</title></head>
<body>
<form action="#" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" name="submit">
</form>
</body>
</html>
<?php
$con=mysqli_connect("localhost","root","","logon");
if(!$con){
echo "not connected";
}else{
echo "connectedsuccessfully";
}
if(isset($_POST['submit']))
{
$name=$_FILES['file']['name'];
$image=$_FILES['file']['tmp_name'];
$sql="insert into image(name,image) values('$name','$image') ";
$res=mysqli_query($con,$sql);
$sqli="select image from image";
$result=mysqli_query($con,$sqli);
$row=mysqli_fetch_array($result);
echo "<br>";
echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['image'] ).'"/>';
}
Output
Akash kumar, you can use the code below to get the image or any file name without extension.
$filename = pathinfo($_FILES['picture']['name'], PATHINFO_FILENAME);
And Echo it. !
your output clearly show that the location of the image is incorrect. and you dont need to use base64_encode. just
echo '<img src="your_path_iamge/"'.$row[image]
[....]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.