我希望显示图片而不是下载图片。
我的数据库表中有图像,列为BLOB。
此代码段会下载图片,但我想改为显示它:
$query = "SELECT * FROM upload";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$content = $row['content'];
$size = $row['size'];
$type = $row['type'];
header("Content-length: $size");
header("Content-type: $type");
// The following headers make the image download, but I don't want it to
// download, I want to show the image. What should I do?
// header("Content-Disposition: attachment; filename=$name");
echo $content;
答案 0 :(得分:3)
attachment
的相反内容处理方式为inline
。试试这个:
header("Content-Disposition: inline; filename=$name");
答案 1 :(得分:1)
如果你想更加动态地使用它来制作原始代码的脚本并按如下方式调用它:
<img src="image.php?imageid=$myImageID" />
你的脚本是:
$myImageID = $_GET["myImageID"];
$query = "SELECT * FROM upload where id='"+$myImageID+"'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$content = $row['content'];
$size = $row['size'];
$type = $row['type'];
header("Content-length: $size");
header("Content-type: $type");
//header("Content-Disposition: attachment; filename=$name");---> this headers make system to download , but i dont want to download, i want to show image, what should i do ,
echo $content; ?>"
答案 2 :(得分:0)
您需要确保除了标题之外的其他内容,并将图像内容发送到客户端。也许你想在echo $ content之后退出;这不是最佳做法,也不能确保在输出图像内容之前没有发送任何其他内容,但它应该可以完成这项工作。
答案 3 :(得分:0)
您可以显示图像,而不用以下代码下载图像:
<a href="myimage.png">Click to download</a>