Hi everyone!

My boss is using a Java program called Animal Shelter Manager, which stores all images as BLOBs (Binary Large OBjects) in the database. She needs me to put all of those pictures she has stored on the shelter's website. I look at them in the database, and they are definitely there, but I have a problem getting them out on a complete web page.

This script can extract and display an image successfully.

if( !( $database = mysql_connect( "********", "********", "********") ) )
				die( "Bad password.");
				
				if ( !mysql_select_db( "asm", $database ) )
					die("Could not open animals database");

header('Content-type: image/jpeg');
$query = "SELECT * FROM dbfs WHERE Path = '/animal/75'";
$result = mysql_fetch_array(mysql_query($query));
echo base64_decode($result["Content"]);

However! Whenever I try to put anything else on the page, such as the most basic echo command, I get this warning "Cannot modify header information - headers already sent by [...]". Then the image's data shows up as raw text.

I have tried putting this script in its own file and then using an include command from another document, but I get the same glitch. So, what am I doing wrong here? How do I extract one of these BLOB images and use them in a web page?

Thank you so much for your help.

-Huiliam

Hi everyone! I solved the problem. It turns out all you need is the following code to successfully display one of these images in a page.

if( !( $database = mysql_connect( "********", "********", "********") ) )
				die( "Bad password.");
				
				if ( !mysql_select_db( "asm", $database ) )
					die("Could not open animals database");

$query = "SELECT * FROM dbfs WHERE ([image column here]) = '[variable you're looking for]'";
$result = mysql_fetch_array(mysql_query($query));
echo '<img src="data:image/jpeg;base64,' . $img . '" />';

Hope this helps someone else.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.