php – 从blob mysql显示图像

嗨,我的数据库中有一个图像表.这些存储为blob以及图像类型和图像等细节.名称.

我在显示图像时遇到问题,我得到的只是一个带有红叉的白色方框.
码:

<?PHP

include '../connection.PHP';

$ID = $_GET['id'];

$query = "SELECT * FROM `images` WHERE `image_id` = '$ID'";

$result=MysqL_query($query);
$row = MysqL_fetch_array($result);

$image = $row['image'];
$image_type= $row['image_type'];   

header("Content-type: $image_type");
print $image; 

exit;

?>

谢谢

解决方法:

那么这是一个简短的答案.

<?PHP
include '../connection.PHP';
$id = (int)$_GET['id'];
$query = "SELECT * FROM `images` WHERE `image_id` = '$id'";

$result=MysqL_query($query);
$row = MysqL_fetch_array($result);

$image = $row['image'];
$image_type= $row['image_type'];
$size = $row['image_size'];
//alternative
/* list($image, $image_type, $size) = array(
                                       $row['image'],
                                       $row['image_type'],
                                       $row['image_size']
                                      );
*/
$ext = explode('/', $image_type);
$name = $id . '.' . $ext[1]; 

header("Content-type: $image_type");
header("Content-length: $size");
header("Content-disposition: attachment; filename=$name");

print $image;     
exit;

检查您的blobtype是最少的MEDIUMBLOB,它能够存储高达16M的数据

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...