Entry
How do I get an image in a mySQL/Oracle (or other) blob fields to display on a regular html page?
Jan 25th, 2000 12:33
Matt Gregory, Onno Benschop,
//The problem is that binary data cannot be inserted directly into
//an html file, so we must trick the browser into thinking it's
//retrieving an image on the webserver. To do this place an
//image tag on the page with the src set to a php script which returns
//nothing but a header and the image. The exampe below will return the
//image and fill in the image tag properly...
//example image tag
<image src="getimage.php3?ImgID=1">
//getimage.php3
if($ImgID != 0)
{
$Query = "Select Image from Images where ImgID = $ImgID";
mysql_connect($DBHOST, $DBUSER, $DBPASS);
mysql_select_db($DATABASE);
$resultset = mysql_query($Query);
if(mysql_affected_rows() > 0)
{
header("Content-type: image/jpeg");
print(mysql_result($resultset, 0, "Image"));
}
}