Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

displaying blobs from an oracle table

Status
Not open for further replies.

bookouri

IS-IT--Management
Feb 23, 2000
1,464
US
I know not to store images in the table, but to store them as files on the file system, but I have to work with what I have here, and what I have is an oracle table with jpegs stored as blobs. I need to display them in a table on a web page.
Here is what I have so far based on examples. But when I run it I get "broken" image placeholders.

PHP:
while ($row = oci_fetch_array($stid, OCI_ASSOC)){
	echo "<tr><td>";
	echo $row['OBJECT_FILE_NAME'];
	echo "</td><td>";
	echo $row['OBJECT_INSERTED_BY'];
	echo "</td><td>";
   	echo '<img src="data:image/jpeg;base64,' . base64_encode( $row['OBJECT_BLOB'] ) . '" />';
		echo "</td></tr>";
}

I have also seen examples like this

PHP:
echo header("Content-type: image/jpeg");
echo $row['image1'];

but it also doesn't work for me. Can anybody point me to the right way to send a page full of images to a web page?


 
there are two stages.

1. output the img tag with appropriate information
2. use the http request from the browser to display the image

so let's say you have a table with the following id, height, width, imageType, data.

you would have a function called getIMGTag as so

Code:
function getImgTag($id, $height, $width){
 $tag = '<img src="%s" height="%s" width="%s" />';
 //do some database getting against the id
 //and if you need to rescale the image to match the height and width, you would do so here
 return sprintf($tag, 'myImageServer.php?imageID='.$id, $height, $width);
 //note that if the image were rescaled and saved with a new id you would replace $id above.
 //OR you could dynamically create and discard rescales on the get side
}

so when the browser receives this html, it will GET the image from the myImageServer.php file and you would need to handle the request there

Code:
<?php
if(!isset($_GET['imageID'])): die('');
//do db stuff to get the right row
switch($row['imageType']):
 case 'jpeg':
 case 'jpg':
 header('Content-Type: image/jpeg');
 break;
 case 'png':
 header('Content-Type: image/jpng');
 break;
endswitch;
header('Content-Length: ' . strlen($row['data']));
echo $row['data'];
die;
?>
 
Thanks, I thought the other examples looked too easy, and I didn't want to waste a lot of time on them if they didn't actually work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top