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

使用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 ...

图片转代码服务由CSDN问答提供 功能建议

所以,我有这个firebird数据库,有一个“照片”列,我试图显示。

这是我到目前为止所做的:

  • 因为,内容类型未知(我不是那个人 创建了数据库,并且没有colomn指示类型)。
  • 从blob数据的前20个字符开始,我猜它是一个bmp。

    下面是一个示例代码:

     在此之前:连接代码,运行查询以获取表并将结果作为对象获取(一切正常,直到此处 )
     
     $ blob_data = ibase_blob_info($ row-&gt; PHOTO); 
     $ blob_hndl = ibase_blob_open($ row-&gt; PHOTO); 
     
     $ bl = ibase_blob_get($ blob_hndl,$ blob_data [0]  ); 
    header('Content-type:image / x-xbitmap'); 
    ibase_blob_echo($ row-&gt; PHOTO); 
     
    echo“&lt; dt&gt;&lt; strong&gt;技术员图片:&lt; / strong&gt;  &LT / DT&GT;&LT峰; dd&gt;”中 。  
    '&lt; img src =“data:image / x-xbitmap; base64,'。
     base64_encode($ bl)。
    '”width =“290”height =“290”&gt;'  。  “&lt; / dd&gt;”; 
     
     $ filename = $ bl?  dirname(__ FILE __)。“/ img / product __ $ NUM.bmp”:dirname(__ FILE __)。“/ img / no_pic.bmp”; 
     
    if($ bl)fwrite(fopen($ filename,'w'),  $ bl); 
       
     
     

    正如您所见,我试过:

    • 显示blob 数据使用“ibase_blob_echo”
    • 使用img标签显示blob
    • 将其另存为文件

      第一个显示blob的原始数据,第二个显示已损坏文件中的第三个结果。

      关于内容类型标题我已尝试 \ n

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

        现在我出去了 想法......

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题