From: Frank Joerdens <frank@joerdens.de>
To: pgsql-php@postgresql.org
Cc: adam@archi-me-des.de
Cc: linuxkurs@fas-art.com
Subject: How to send bytea data straight to browser (as in pg_loreadall)?
Date: Mon, 1 Apr 2002 20:31:01 +0200
Message-ID: <20020401203101.A13198@superfly.archi-me-des.de> (raw)
I don't seem to be able to get my head 'round as to how to do this. It
works OK if I do something like
---------------------- begin snippet ----------------------
$query = "SELECT * FROM bytea_test;";
$conn = pg_pconnect("host=192.168.100.70 dbname=bytea_test");
$result = pg_exec($conn, $query);
$i = 0;
while (@pg_result($result, $i, id)) {
$fp = fopen('/usr/local/httpd/htdocs/testfile'.$i.'.gif', 'w');
fwrite($fp, stripcslashes(pg_result($result, $i, image)));
echo "<img src=\"";
echo 'testfile'.$i.'.gif';
echo "\">";
$i++;
}
---------------------- end snippet ----------------------
which means that I create a file for each image pulled from the database
and then put this file path (relative to http root) into an img tag.
That's rather stupid though, because it's unnecessary, slow, and bound
to give concurrency trouble.
I've played with fgets, fwrite, fputs, fpassthrough, trying to make a
file pointer on stdout with fopen . . . it appears that I don't
understand some crucial point about how this works. How do you present
an image to the browser without actually creating a file for it? The
built in function pg_loreadall appears to do exactly that. I'd need to
replicate that functionality for bytea.
Regards, Frank
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: frank@joerdens.de, adam@archi-me-des.de, linuxkurs@fas-art.com
Subject: Re: How to send bytea data straight to browser (as in pg_loreadall)?
In-Reply-To: <20020401203101.A13198@superfly.archi-me-des.de>
References: <20020401203101.A13198@superfly.archi-me-des.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox