php中不可读格式的图像显示
我使用以下代码显示数据库中的图像此代码以不可读的格式获取图像,在数据库中我在blob中创建图像类型请帮助我在用户输入图像名称时动态显示图像它应仅显示该图像 我的数据库表 表名存储php中不可读格式的图像显示,php,Php,我使用以下代码显示数据库中的图像此代码以不可读的格式获取图像,在数据库中我在blob中创建图像类型请帮助我在用户输入图像名称时动态显示图像它应仅显示该图像 我的数据库表 表名存储 id | name |image --------------- 1 | xxxx| (image) <?php mysql_connect("localhost","root","")or die(mysql_error()); mysql_select_db("databaseimage") or die
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();
?>
试试这个:
header("Content-type: image/jpeg");
echo mysql_result($result, 0);
基本上有两种可能的选择。是否使用数据URI方案。我通常更喜欢使用2个没有数据uri的脚本。这些只是给你一个想法的例子,所以你可能需要编辑代码 一,。您需要2个脚本来创建带有图像的表 table.php 二,。您需要1个脚本来创建带有图像的表 table.php
看看这个答案,它应该会帮助您在这个表中不显示图像。如果我的数据库表中有更多图像,我如何从该表中搜索特定图像并显示。@abbas这两种情况都希望图像是PNG文件格式。如果不是,则无法显示图像,因为它们与标题image/png一起提供。若它们是其他格式,您需要指定不同的头,例如,您可以将mime类型保存到数据库。要显示有关图像的更多信息,可以使用示例echo.$row['image']。;对于搜索特定图像,您可以使用:$sql=从名称为“%searching_this_image%”的存储中选择图像;
<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');
}
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();