使用PHP从Firebird数据库显示Blob数据 [英] Displaying blob data from a firebird database using PHP

查看:107
本文介绍了使用PHP从Firebird数据库显示Blob数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有这个firebird数据库,其中有一个"photo"列,直到我要显示.

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

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

Here is what i've done so far:

  • 因为,内容类型是未知的(我不是创建数据库的人,并且没有表示该类型的列).
  • 从blob数据的前20个字符开始,我想它是bmp.

这是示例代码:

 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 :

  • 使用"ibase_blob_echo"显示斑点数据
  • 使用img标签显示blob
  • 将其另存为文件

第一个显示Blob的原始数据,第二个不显示任何内容,第三个显示损坏的文件.

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

关于我尝试过的Content-type标头

Concerning the Content-type header i've tried

  • 图像/bmp,x便携式位图,x-x位图,jpg,gif,png

现在我没主意了...

Now i'm out of ideas ...

推荐答案

作为位图 >在位置0处具有0x42 0x4D,然后是文件大小的4个字节(0x36 0x65 0x01 0x00).在转储中,您发布的字节5-8(在BMP标头之前)和字节11-14(在BMP标头之后的文件大小)是相同的,因此看起来blob具有(猜测功能):

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个字节:某种特定于应用程序的图像类型nr(?)
  • 4个字节:文件大小(与0x42 0x4D之后相同)
  • 实际位图文件

您可能要检查跳过前8个字节是否足以使其正常工作,然后我将检查所有文件是否通用(也许有多个文件类型!)

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

这篇关于使用PHP从Firebird数据库显示Blob数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆