I have been trying to display image from database using php but i am only getting download prompt whenever i use or click the link. what i want to do is, i want to display it on the web browser. And want to use it in tags.
my code is:
require_once('dbconfig.php');
$cont=mysql_connect($dbhost,$dbuser,$dbpass) or die("Error Connecting the Database");
$seldatabase=mysql_select_db($dbselect,$cont);
$insert = "SELECT `p_mime`, `p_name`, `p_size`, `p_data` FROM $dbtbl_reg_details WHERE `id` = $id";
$query = mysql_query($insert);
if ($query)
{
if (mysql_num_rows($query)==1)
{
$row = mysql_fetch_assoc($query);
header("Content-Type: image/png");
header("Content-Length: ". $row['p_size']);
header("Content-Disposition: inline; filename=". $row['p_name']);
echo $row[p_data];
}
else
{
echo "image with id = ".$id." does not exist";
}
}
else
{
echo "query failed, image with id = ".$id." does not exist";
}
And when i use inline for Content-Disposition: then my web page returns a script error on the browser.
So, what should i do to display images on web pages while retrieving it from mysql database
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…