2014-02-06 16:41
浏览 120


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

echo "<dt><strong>Technician Image:</strong></dt><dd>" . 
     '<img src="data:image/x-xbitmap  ;base64,'.
      '" 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问答提供 功能建议



  • 因为,内容类型未知(我不是那个人 创建了数据库,并且没有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
    • 将其另存为文件


      关于内容类型标题我已尝试 \ 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!)

    解决 无用
    打赏 举报

相关推荐 更多相似问题