我使用以下代码显示数据库中的图像此代码以不可读的格式获取图像,在数据库中我在“blob”中创建图像类型请帮助我在用户输入图像名称时动态显示图像应该只显示该图像
我的数据库表 表名商店
id | name |image
---------------
1 | xxxx| (image)
<?php
mysql_connect("localhost","root","")or die(mysql_error());
mysql_select_db("databaseimage") or die(mysql_error());
$query = "SELECT * FROM store where fname = 'ss' ";
$info = mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($info);
$sql ="select image from store where fname = 'ss' ";
$result = mysql_query($sql) or die(mysql_error());
if($result){
echo'
<table align="center" cellspacing="0" cellpadding="5" bgcolor="#ffffff" border=1 bordercolor="#2696b8">
<tr>
</tr>';
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo'<tr>
<td align="center" width="150" height="200"><img src="datadesign.php' . $row['image'] . '">
</tr>';
}
echo'</table>';
}
else{
echo'<h1> System Error </h1> table ';
exit();
}
mysql_close();
?>
答案 0 :(得分:0)
试试这个:
header("Content-type: image/jpeg");
echo mysql_result($result, 0);
答案 1 :(得分:0)
基本上有2种可能的选择。是否使用数据URI方案(http://en.wikipedia.org/wiki/Data_URI_scheme)。我通常更喜欢使用没有数据uri的2个脚本。这些只是给你一个想法的例子,所以你可能需要编辑代码。
<强> 1。您需要2个脚本来创建带图像的表格。
<table align="center" cellspacing="0" cellpadding="5" bgcolor="#ffffff" border=1 bordercolor="#2696b8">
<tr>
<td align="center" width="150" height="200"><img src="image.php?image_id=1">
</tr>
</table>
mysql_connect("localhost","root","")or die(mysql_error());
mysql_select_db("databaseimage") or die(mysql_error());
$sql ="select image from store where id= '".intval($_GET['image_id'])."' ";
$result = mysql_query($sql) or die(mysql_error());
header('Content-Type: image/png');
if($result){
$row = mysql_fetch_row($result);
echo $row['image'];
mysql_close();
}
else
{
echo readfile('/your/path/error/image.png');
}
<强> 2。您需要一个脚本来创建带图像的表格。
mysql_connect("localhost","root","")or die(mysql_error());
mysql_select_db("databaseimage") or die(mysql_error());
$query = "SELECT * FROM store where fname = 'ss' ";
$info = mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($info);
if ($num > 0)
{
echo'
<table align="center" cellspacing="0" cellpadding="5" bgcolor="#ffffff" border=1 bordercolor="#2696b8">
<tr>
</tr>';
while($row = mysql_fetch_array($info, MYSQL_ASSOC)){
echo'<tr>
<td align="center" width="150" height="200"><img src="data:image/png;base64,'.base64_encode($row['image']). '">
</tr>';
}
echo'</table>';
}
mysql_close();