1

So, I have this Firebird database, with a "photo" column which 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 column indicating the type).

  • From the first 20 character of the blob data I guess it's a bmp:

    "01 00 00 01 36 65 01 00 42 4D 36 65 01 00 00 00"

    The "42 4D" is in every photo I get.

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.

3
  • Post the hex of the first 20 bytes. Commented Feb 8, 2014 at 12:53
  • "01 00 00 01 36 65 01 00 42 4D 36 65 01 00 00 00" The "42 4D" is in every photos i get. Commented Feb 10, 2014 at 14:35
  • i know this is old, but can you tell me how did you insert the blob in the database? im trying to insert the blob but it is only inserting like 0x000usi354sf0000 Commented Sep 1, 2021 at 13:19

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

1 Comment

Well skipping the first 8 bytes worked like a charm. I used a simple substr() and it worked. Thanks for the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.