dqvy87517 2014-02-06 16:41
浏览 122
已采纳

使用PHP从firebird数据库显示blob数据

So, i have this firebird database, with a " photo " column wich i'm trying to display.

Here is what i've done so far:

  • Since ,the content type is unknown ( I'm not the one who created the database, and there is no colomn indicating the type).
  • From the first 20 character of the blob data i guess it's a bmp.

Here's a sample code :

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

As you can see i've tried to :

  • Display the blob data using "ibase_blob_echo"
  • Display the blob using img tag
  • Save it as a file

First one show raw data of the blob, the second nothing and the third result in a corrupted file.

Concerning the Content-type header i've tried

  • image/bmp ,x-portable-bitmap, x-xbitmap , jpg, gif, png

Now i'm out of ideas ...

  • 写回答

1条回答 默认 最新

  • dongxingji3882 2014-02-11 10:27
    关注

    As a bitmap has 0x42 0x4D at position 0, and then 4 bytes of file size (0x36 0x65 0x01 0x00). In the dump you posted both bytes 5 - 8 (before the BMP header) and bytes 11-14 (filesize after BMP header) are the same, so it look like the blob has (guess work):

    • 4 bytes: some kind of application specific image type nr (?)
    • 4 bytes: file size (same as after the 0x42 0x4D)
    • Actual bitmap file

    You might want to check if skipping the first 8 bytes is enough to get it to work, then I'd check if this is generic across all files (maybe there is more than one file type!)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献