Displaying picture data stored in a blob field

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
alex317
Forum Newbie
Posts: 2
Joined: Mon Sep 23, 2002 9:04 am

Re: Picture data in a blob field?

Post by alex317 »

Hi all, :oops:

I have a picture in a blob field and as well as primary key called id.

And ihave created a page that have the following tag:
<IMG SRC="getblob.php?id=$id">

The content of getblob.php:

<?php
require("sid.inc");
$conn = jaltLogon(); //login to my oracle 8i database
$sql = OCIParse($conn,"select photo from testBLOB where id=".$id);
OCIExecute($sql, OCI_DEFAULT);
OCIFetchInto($sql, $row, OCI_RETURN_LOBS);
$lob_data = $row->load();
print $lob_data;

OCIFreeStatement($sql);
OCILogoff($conn);
?>

However, the page cannot display the blob field...

Any suggestion? :?:

Thanks You...
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

It makes it easier for us to help you if you tell us what is happening when the script is run and include any error messages that you might be receiving.

That said, you need to use the header() function to add a header which has the images type (gif/jpg/png) in it so that the browser knows what to do with the information.

So before you echo the blob data to the browser you need a line like:

Code: Select all

header("content-type: image/gif\r\n");
edited to reflect the kind of image you are displaying.

Mac
alex317
Forum Newbie
Posts: 2
Joined: Mon Sep 23, 2002 9:04 am

broken images displayed...

Post by alex317 »

When i retrieve an image from database and display to a html, the image always seems incomplete or can be say as broken.

And sometimes, the broswer return a "page not found" error.

Why it is cause and any suggestion? Thanks you very much.

The code i used to get the images (assume all the image is in gif format)....

Code: Select all

<?php
	require("sid.inc");
	$conn = jaltLogon();
	$sql = OCIParse($conn,"select photo from testBLOB where id=".$id); 
	
	OCIExecute($sql, OCI_DEFAULT);
	OCIFetchInto($sql, $row, OCI_RETURN_LOBS);
	
	$lob_data = $row&#1111;0];
	
	header("content-type: image/gif\r\n");
	print $lob_data;

	OCIFreeStatement($sql);
	OCILogoff($conn);
?>
Again... Thanks you very much :D
Post Reply