【发布时间】:2014-12-03 22:07:12
【问题描述】:
我正在使用 smarty,mysql,我只是想显示图像。 这是我得到的错误 -
资源解释为图像,但使用 MIME 类型 text/html 传输
我的 index.php 文件
<img src="http://localhost/admin/image2.php?id={$editWine[0].id}" width="150" height="260" border="0" class="bottle-img" id="smallImageWineEdit" />
我的 image2.php 文件
$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" />  ';
echo $row['image_data'];
}
while 循环中的这个 echo 工作正常。
当我检查元素并在新选项卡中打开这个 img 链接时,图像正在显示。而它没有显示在当前页面中。
【问题讨论】:
-
为什么要在 index.php 中加倍
<img>标签并作为 image2.php 的输出? index.php 中的<img>标记期望内容类型为图像,但您从 image2.php 发回带有<img>标记列表的 html 代码,其中包含数据 uris 而不是内容类型图像和图像的二进制代码。 -
@Cheery。我只是在检查图像是否正在显示。
-
所以,它没有显示,因为您没有将图像发送回浏览器。
-
我在 index.php 的
标签中使用 id.. 调用我的 image2.php
-
你不明白 http 请求是如何工作的。看看下面提供的答案。