我想显示图像而不是下载它(数据库 blob 中的图像)

Bha*_*mar 7 php

我想显示图像而不是下载它。

我的数据库表中有图像,列为 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;
Run Code Online (Sandbox Code Playgroud)

mea*_*gar 7

的相反内容处置attachmentinline。尝试这个:

header("Content-Disposition: inline; filename=$name");
Run Code Online (Sandbox Code Playgroud)


Cri*_*tiC 1

如果您想更动态地使用它,请制作原始代码的脚本并按如下方式调用它:

<img src="image.php?imageid=$myImageID" />
Run Code Online (Sandbox Code Playgroud)

你的脚本是:

$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; ?>"
Run Code Online (Sandbox Code Playgroud)