pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joe Conway <mail@joeconway.com>
To: Frank Joerdens <frank@joerdens.de>
Cc: pgsql-php@postgresql.org
Cc: adam@archi-me-des.de
Cc: linuxkurs@fas-art.com
Subject: Re: How to send bytea data straight to browser (as in pg_loreadall)?
Date: Mon, 01 Apr 2002 13:22:05 -0800
Message-ID: <3CA8CF7D.9060303@joeconway.com> (raw)
References: <20020401203101.A13198@superfly.archi-me-des.de>

Frank Joerdens wrote:
> 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

I've always approached this a bit differently, but in any case, did you 
try to use "php://stdout"? If not see: 
http://www.php.net/manual/en/function.fopen.php


I usually create one php file to generate the image output, and a second 
one which calls the first. E.g. (untested)

---------------------- begin showimgage.php ----------------------
<?PHP

$conn = pg_pconnect("host=192.168.100.70 dbname=bytea_test");
$query = "SELECT img FROM bytea_t where id=" . $_GET["imgid"];
$result = pg_exec($conn, $query);

$image = stripcslashes(pg_result($result, 0, 0));
// send the image
header("content-type: image/gif");
echo $image;

?>
---------------------- showimgage.php ----------------------

The second file would then have a line like:

echo "<img src='showimage.php?imgid=1' border=0>";


Hope this helps,

Joe






view thread (3+ messages)

Message-ID: <3CA8CF7D.9060303@joeconway.com>
Permalink:  ../3CA8CF7D.9060303@joeconway.com/
Also on:    postgresql.org/message-id/3CA8CF7D.9060303@joeconway.com

 · 

reply

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: mail@joeconway.com, 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: <3CA8CF7D.9060303@joeconway.com>
  References: <20020401203101.A13198@superfly.archi-me-des.de> <3CA8CF7D.9060303@joeconway.com>

* 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