Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在php中显示数据库中的图像_Php_Mysql_Blob - Fatal编程技术网

无法在php中显示数据库中的图像

无法在php中显示数据库中的图像,php,mysql,blob,Php,Mysql,Blob,我正在使用smarty、mysql,我只是想显示图像。 这就是我得到的错误- 资源被解释为图像,但使用MIME类型text/html传输 我的index.php文件 我的image2.php文件 $id=$\u请求['id']; $sql=“从id=$id的表中选择*”; $result=mysql\u query($sql)或die(mysql\u error()); while($row=@mysql\u fetch\u assoc($result)) { 回音'; echo$row['

我正在使用smarty、mysql,我只是想显示图像。 这就是我得到的错误-

资源被解释为图像,但使用MIME类型text/html传输

我的index.php文件

我的image2.php文件
$id=$\u请求['id'];
$sql=“从id=$id的表中选择*”;
$result=mysql\u query($sql)或die(mysql\u error());
while($row=@mysql\u fetch\u assoc($result))
{
回音';
echo$row['image_data'];
}
当环路正常工作时,内部会出现回声


当我检查元素并在新选项卡中打开此img链接时,显示的是图像。然而它并没有显示在当前页面中。

问题是您再次从图像文件中传递html标记。您只需要输出具有适当图像内容类型的图像数据

编辑
image2.php
like

if($row=@mysql_fetch_assoc($result))
{
   header('Content-type: image/jpg');
   echo $row['image_data'];
   exit();                   
}
更新以下评论
执行上述更改并请求
http://localhost/admin/image2.php?id=VALID_ID_HERE
并检查其是否重新调整图像。然后可以在
index.php
的src标记中使用它来显示它。如果在渲染图像时出错,那么在请求时,请确保在数据库中询问正确的图像id,并使用看到的错误消息更新问题。

为什么在index.php和image2.php的输出中双重标记
index.php中的标记要求内容类型为图像,但您正在从image2.php返回html代码,其中包含带有数据URI的
标记列表,而不是内容类型图像和图像的二进制代码。@Cheery。我只是在检查图像是否正在显示。所以,它没有显示,因为您没有将图像发送回浏览器。我正在使用id调用index.php标记中的image2.php。您不了解http请求是如何工作的。请看下面提供的答案。谢谢。。我试过。。但是我想在index.php中显示我的图像。
image.php
?你的问题中只有
image2.php
index.php
?您指的是哪个文件?@user3918082:没问题:)
$id=$_REQUEST['id'];        
$sql="SELECT * FROM table WHERE id=$id";        
$result=mysql_query($sql) or die(mysql_error());
while($row=@mysql_fetch_assoc($result))
{
   echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['image_data'] ).'" width="150" height="150" /> &nbsp';  
   echo $row['image_data'];                     
}
if($row=@mysql_fetch_assoc($result))
{
   header('Content-type: image/jpg');
   echo $row['image_data'];
   exit();                   
}