Well, why not just write the code right here:
First, we need a table to hold our images:
test=> CREATE TABLE images (
id serial NOT NULL,
filename text
);
test=> insert into images (filename) values ('applications.png');
test=> insert into images (filename) values ('daily_news.png');
test=> insert into images (filename) values ('documentation.png');
test=> insert into images (filename) values ('entertainment.png');
Then we can write a program to view the images:
<?php
header("Content-type: image/png");
$conn = pg_connect("user=test dbname=test");
$table = "images";
# Put an addslashes here if you're not running with magic_quotes_gpc on
# $id = addslashes($id);
$query = "select * from images where id='$id'";
$res = pg_query($conn,$query);
$path = "/usr/local/apache/htdocs/images/";
if (@pg_numrows($res)!=0){
$filename = pg_result($res,0,'filename');
$fp = fopen($path.$filename,"r");
$img = fread($fp,10000000);
print $img;
} else {
die();
}
?>
And lastly we can now reference it from an html doc like so:
<HTML><HEAD><TITLE>main</TITLE></HEAD>
<BODY>
<img src="viewimage.html?id=1">
</BODY></HTML>
Note that with this setup the images directory does NOT have to be in the document root of your apache server, it could be anywhere apache / php can get to.