0

我将图像存储在 mySQL 服务器上作为 mediumblob。当我尝试使用以下代码显示它们时,某些浏览器(例如 safari 和 EI)会下载图像而不是显示它们。有没有办法显示它们独立于浏览器?

$query = "SELECT image FROM images WHERE id=?";
$stmt = $dbc->prepare($query);
$stmt->bind_param("i",$id);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($image);
$stmt->fetch();
header("Content-Type: image/jpg");
echo $image;

提前致谢

4

3 回答 3

4

尝试Content-Type: image/jpeg代替Content-Type: image/jpg

image/jpeg是 jpeg 图像的正确 MIME 类型。

于 2012-04-15T01:19:05.247 回答
3

尝试发送Content-Disposition具有这样值的标头inline

$query = "SELECT image FROM images WHERE id=?";
$stmt = $dbc->prepare($query);
$stmt->bind_param("i",$id);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($image);
$stmt->fetch();
header("Content-Type: text/html");
header("Content-Disposition: inline");
echo $image;
于 2012-04-15T01:25:03.840 回答
0

试试这个

$query = "SELECT image FROM images WHERE id=?";
$stmt = $dbc->prepare($query);
$stmt->bind_param("i",$id);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($image);
$stmt->fetch();
header("Content-Type: text/html");
echo $image;

或者

$query = "SELECT image FROM images WHERE id=?";
$stmt = $dbc->prepare($query);
$stmt->bind_param("i",$id);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($image);
$stmt->fetch();
header("Content-Type: image/jpg");
echo "<p>".$image."</p>";

另请注意,如果没有 HTML 内容,某些浏览器会下载图像。你试过其他浏览器吗?

于 2012-04-15T01:20:06.567 回答