我从MySQL DB中重新获取了BLOB图像,但它没有出现在浏览器上

时间:2016-07-04 14:49:08

标签: php mysql blob

我已将图像插入到mySQL DB中,但图像未显示。这是我的代码(我已离开其他块,如php,DB连接和基本HTML标签):(它用于学习目的)

HTML表格:

<label for="user_pic">Upload a picture:</label>
    <input type="file" id="user_pic" name="user_pic" size="30" /> <br />

INSERT.php

$image = $_FILES[$image_fieldname];
$image_filename = $image['name'];
$image_info = getimagesize($image['tmp_name']);
$image_mime_type = $image_info['mime'];
$image_size = $image['size'];
$image_data = file_get_contents($image['tmp_name']);

$insert_image_sql = sprintf("INSERT INTO images (filename,mime_type,file_size,image_data) VALUES ('%s','%s',%d ,'%s');",mysql_real_escape_string($image_filename),mysql_real_escape_string($image_mime_type),mysql_real_escape_string($image_size),mysql_real_escape_string($image_data));

mysql_query($insert_image_sql)
or die(mysql_error());

SHOW.php

$image_id = $_REQUEST['image_id'];
$select_query = sprintf("SELECT * FROM images WHERE image_id = %d",$image_id);
$result = mysql_query($select_query);
$image = mysql_fetch_array($result);
header('Content-type: ' . $image['mime_type']);
header('Content-length: ' . $image['file_size']);


echo $image['image_data'];

0 个答案:

没有答案