1

I have a SQL server database that has a varbinary(max) column that contains data for a bitmap image. I need to display this data as an image on a PHP page.

Any idea how I would go about this? I havn't found alot of information on the internet as to how to do it.

When I look at the data through the management studio, it looks like 0x42DBE3400000..., whereas if I retrieve it thorugh ODBC and echo it to the screen, it looks like Qk2+NAAAAAAAAD4AAAAoAAAArgEAAPAAAAAB.

I havn't worked very much with binary data before so I'm not sure what to do from here! Any help appreciated

2

1 Answer 1

1

In order for the page to not look like garbled text, you will need to output a Content-Type header in order for the browser to recognize that the page is an image and not a text/html page.

<?php
header('Content-Type: image/x-bmp');

echo '{display the image's binary content here}';
?>
Sign up to request clarification or add additional context in comments.

9 Comments

Thanks for the response. I've used the following code, but I still get just characters: <?php include("../../../cfg.inc"); require_once($dir["base"]["inc"] . "supplymaster.inc"); $status = get_pod("R1","PAG","123"); if ( $status !== NULL ) { header("Content-type: image/x-bmp"); echo $status; exit; } ?>
Do any of the included files output any information? Such as HTML or even other headers? If the system you're testing on is open to the public, you can try using this HTTP header viewer and see if the Content-Type header is not getting through.
Hi. No none of the include files do. I created a string with just the data from the query itself and got the same result. The page is on the web, but behind a private area. Does firebug show me this information?
I've just gone to the page again and it showed up a download window, so im sure the content-type is working. When I opened with windows picture viewer, it couldnt open it. When viewing the data in SQL server, is that in HEX format I'm guessing? I saved the data from there into a variable, and used hextobin before echoing, but still no cigar :(
Do you use output buffering (ob_start, ob_start('ob_gzhandler'), etc)? How are you saving the image to the database? Are you sure it is binary safe?
|

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.