Page 1 of 1

Re: Picture data in a blob field?

Posted: Mon Sep 23, 2002 9:04 am
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...

Posted: Mon Sep 23, 2002 9:17 am
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

broken images displayed...

Posted: Tue Sep 24, 2002 7:32 am
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