【发布时间】:2020-12-31 23:03:40
【问题描述】:
所以,我有这个 Firebird 数据库,其中包含一个我正在尝试显示的“照片”列。
这是我到目前为止所做的:
-
由于内容类型未知(我不是创建数据库的人,并且没有指示类型的列)。
-
从 blob 数据的前 20 个字符我猜它是一个 bmp:
“01 00 00 01 36 65 01 00 42 4D 36 65 01 00 00 00”
“42 4D”出现在我得到的每张照片中。
这是一个示例代码:
// Before this : code to connect, run a query to get the table and fetch the result as object ( everything works fine until here)
$blob_data = ibase_blob_info($row->PHOTO);
$blob_hndl = ibase_blob_open($row->PHOTO);
$bl = ibase_blob_get($blob_hndl, $blob_data[0]);
header('Content-type : image/x-xbitmap');
ibase_blob_echo($row->PHOTO);
echo "<dt><strong>Technician Image:</strong></dt><dd>" .
'<img src="data:image/x-xbitmap ;base64,'.
base64_encode($bl).
'" width="290" height="290">' . "</dd>";
$filename = $bl ? dirname(__FILE__)."/img/product__$NUM.bmp" : dirname(__FILE__)."/img/no_pic.bmp";
if ($bl) fwrite(fopen($filename, 'w'), $bl);
如你所见,我已经尝试过:
- 使用“ibase_blob_echo”显示 blob 数据
- 使用 img 标签显示 blob
- 另存为文件
第一个显示 blob 的原始数据,第二个什么都没有,第三个导致文件损坏。
关于我尝试过的 Content-type 标头
- 图像/bmp ,x-portable-bitmap, x-xbitmap , jpg, gif, png
现在我没有主意了。
【问题讨论】:
-
发布前 20 个字节的十六进制。
-
"01 00 00 01 36 65 01 00 42 4D 36 65 01 00 00 00" 我得到的每张照片中都有“42 4D”。
-
我知道这是旧的,但你能告诉我你是如何在数据库中插入 blob 的吗?我试图插入blob,但它只是插入
0x000usi354sf0000