HI kc,
Maybe this'll work ... create a file, image.php say ...
<?php
// File:image.php
include("C:/topsecret.php");
if(!isset($_REQUEST['Rid'])){
$_REQUEST['Rid'] = 8; // Or some other default
}
// Connect to db
$link = mysql_pconnect($mysqlhost, $mysqluser, $mysqlpasswd)
or die(mysql_error());
mysql_select_db($mysqldbname, $link)
or die(mysql_error());
//select respective image
$sql = "SELECT * FROM image WHERE Rid = '".$_REQUEST['Rid']."'";
$result = mysql_query($sql, $link)
or die(mysql_error());
if(!mysql_numrows($result)){
die('No such image exists');
}
$pic = mysql_fetch_array($result);
header("Content-type: image/".$pic['Type']);
echo $pic['Content'];
?>
... which just delivers an image, according to a variable passed to it (in this case $Rid, but whatever).
Then, whenever you want an image from the database, you use ...
<img src="image.php?Rid=8">
... and you can put that wherever you need.
The only issue is what happens when something goes wrong (one of those 'die' statements occurs). I would consider returning a default image, maybe using fopen on a static jpg on the server and echo the contents instead of $pic['Content']. Plenty in the manual on how to do this.
Hope that helps.
Paul 🙂