Re: [GENERAL] Postgres Large Object
| From: | Peter Mount | Date: | Tue, 19 Sep 2000 18:21:15 +0000 |
| Subject: | Re: [GENERAL] Postgres Large Object | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-2973@lists.php.net to get a copy of this message | ||
On Tue, 19 Sep 2000, Enrico Comini wrote:
> Hi,
> I' m a newbie with BLOBS.
> I have pg-database with images in large object.
> I read (with php) the blob but how to see this image ?
The best way is to have a separate php script which is called with the oid
as a parameter. It then reads the blob and returns the contents.
Ok, this is from scratch, so I don't know if it would work, but here's the
theory:
This is a file called lojpg.php:
<?
$conn=pg_connect("","","","","mydb");
.. open db here
$r=pg_Exec("Begin");
if($r) {pg_FreeResult($r);}
$h=pg_loopen($conn,$oid,"r");
$img=pg_loreadall($h);
pg_loclose($h);
$r=pg_Exec("end");
if($r) {pg_FreeResult($r);}
header("Content-Type: image/jpeg");
echo $img;
?>
Now in your other php page (or any html page), refer to the lo as:
<img src="lojpg.php?oid=68129">
Obviously this example assumes that the image is a jpeg, but you can fix
that by handling the mime type correctly.
Peter
--
Peter T Mount peter@retep.org.uk http://www.retep.org.uk
PostgreSQL JDBC Driver http://www.retep.org.uk/postgres/
Java PDF Generator http://www.retep.org.uk/pdf/