显示来自blob mysql的图像 [英] show image from blob mysql

查看:59
本文介绍了显示来自blob mysql的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有一张图片表.这些与细节一起存储为Blob,例如图像类型&名称.

Hi I have a image table in my database. These are stored as blob along with details such as image type & name.

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

I am having a problem showing the image, all I get is a white box with a red cross in it. code:

<?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;

检查您的Blob类型至少为MEDIUMBLOB,它能够存储高达16M的数据

Check your blobtype to be a least MEDIUMBLOB which is able to store data up to 16M

这篇关于显示来自blob mysql的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆