php读取MYSQL数据库中的longblob字段(图片)并输出到浏览器端。

2025-04-08 14:32:32
推荐回答(1个)
回答1:

要做为图片输出需要设置header就可以了,在上传图片的时候最好记录一下图片类型,大小。

//从数据库读,这里就不具体写了
$row = DataClass::query("select * from images where id=$id");

header('Content-type: ' . $row['type']);  
header('Content-Length: ' . $row['size']); 
header("Content-Transfer-Encoding: binary"); 
ob_clean(); //防止php将utf8的bom头输出
echo $row['content']; //直接输出longblob字段的内容