Reputation: 434
I have an issue rendering stored images from phpmyadmin database.
I have two files, first one is image.php ,which is suppose to retrieve the images from database :
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$conn = mysqli_connect("hostname","username","password");
if(!$conn)
{
echo mysql_error();
}
$db = mysqli_select_db("imagestore");
if(!$db)
{
echo mysql_error();
}
$ano = $_GET['ano'];
$q = "SELECT aphoto,aphototype FROM animaldata where ano='$ano'";
$r = mysqli_query("$q",$conn);
if($r)
{
$row = mysqli_fetch_array($r);
$type = "Content-type: ".$row['aphototype'];
header($type);
readfile($ano);
echo mysql_real_escape_string.$row['aphoto'];
}
else
{
echo mysql_error();
}
?>
and show.php , which is suppose to show the retrieved image :
<?php
//show information
ini_set('display_errors',1);
error_reporting(E_ALL);
include "connect.php";
$q = "SELECT * FROM animaldata";
$r = mysqli_query($conn,$q);
if($r)
{
while($row=mysqli_fetch_array($r))
{
//header("Content-type: text/html");
echo "</br>";
echo $row['aname'];
echo "</br>";
echo $row['adetails'];
echo "</br>";
//$type = "Content-type: ".$row['aphototype'];
//header($type);
echo "<img src=image.php?ano=".$row['ano']." width=300 height=100/>";
}
}
else
{
echo mysql_error();
}
?>
When I try show.php i get this result:
I would be very grateful for any help, because i tried many different codes but i could not find the solution and still getting the same result.
Thank you.
Upvotes: 1
Views: 72
Reputation: 2156
You should get rid of the readfile
line as it is not needed and also the mysqli_real_escape_string
from the line below. Otherwise this looks like it could work, but without knowing how you stored the images I can't know for sure. For example, if you stored them base64 encoded then you'd need to echo the the base64 decoded string.
Upvotes: 1