嗨,我的数据库中有一个图像表.这些存储为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的数据