嗨,我的数据库中有一个图像表。这些与细节一起存储为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;
检查您的Blob类型是否至少为MEDIUMBLOB,它能够存储高达16M的数据