我一直在尝试使用php显示数据库中的图像,但是我只有在我使用或单击链接时才会下载提示。我想要做的是,我想在Web浏览器上显示它。并希望在标签中使用它。如何显示使用PHP存储在mysql数据库中的图像
我的代码是:
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";
}
当我使用内联的内容处置:然后我的网页返回浏览器上的脚本错误。
所以,我应该做些什么来显示网页上的图片,同时从mysql数据库
为什么你要存储在数据库中的图像? – 2010-08-16 08:12:57
相关:http://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay – 2010-08-16 08:31:38