OK, here's how you do it.
The following is a PHP file, that is called with this HTML:
<img src="showavatar.php?id="<?php echo mysql_result($avatardetail, 0, "ID"); ?>">
The idea is that the user uploads a graphic into the database, which is then used as an avatar in my forums page.
So, showavatar.php creates a file, which is passed straight to the browser as an Image.
<?php
require("tools.php");
if(isset($id))
{
$filedata = mysql_query("SELECT * FROM forumAvatars WHERE ID = '".$id."' LIMIT 1");
header("Content-type: \"".mysql_result($filedata, 0, "filetype")."\"");
// Work out whether we can show or download the attachment:
$mimetype = explode("/", $row["filetype"]);
if($mimetype[0] != "image")
{
header("Content-length: ".mysql_result($filedata, 0, "filesize"));
header("Content-Disposition: attachment; filename=".mysql_result($filedata, 0, "filename"));
header("Content-Description: PHP Generated Data");
}
echo mysql_result($filedata, 0, "Avatar");
}
?>
The core thing here is that if you are wishing to display the image, you just fire it at the browser. Otherwise, you pass the header information, and the browser will show a download screen.
Hope that helps!