pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mihail Mihailov <Mihail.Mihailov@uta.fi>
To: Dave Page <dpage@postgresql.org>
Cc: Mihail Mihailov <Mihail.Mihailov@uta.fi>
Cc: pgsql-php@postgresql.org
Subject: Re: php, postgresql and graphical images
Date: Wed, 13 Jun 2007 23:06:11 +0300
Message-ID: <20070613230611.mewiitg4mnco8kwo@imp3.uta.fi> (raw)
In-Reply-To: <466FB441.6000204@postgresql.org>
References: <20070613115155.uykzmxtvxueoo4w8@imp3.uta.fi>
	<466FB441.6000204@postgresql.org>

Hi Dave and thanks for advice.

You show in your example how to create an html file containing only  
one picture.
How do you insert multiple graphical images into a "mixed" document  
containing text and graphical images?
Do I still have to save bytea data into a temporary file (how?) and  
than get in with <img> tag?

Sorry for stupid questions :-)

Mike

>
>> Are there any other ways to export images from the database?
>
> Hi Mike,
>
> I store them in bytea columns, along with their mimetype, then use a
> script like:
>
> <?php
>
> require "db.php";
>
> $sql = "SELECT image_data, image_mimetype FROM images where id = " .
> intval($_GET['id']);
>
> $res = pg_query($GLOBALS['db'], $sql);
>
> if (pg_numrows($res) != 1)
> {
>   header("HTTP/1.0 404 Not Found");
>   exit();
> }
>
> $image = pg_unescape_bytea(pg_result($res, 0, 0));
> $mimetype = pg_result($res, 0, 1);
>
> header("Expires: " . date("D, j M Y H:i:s", time() + (86400)) . " UTC");
> header("Cache-Control: Public");
> header("Pragma: Public");
>
> header("Content-Type: " . $mimetype);
> echo $image;
>
> ?>
>
> I should really rewrite that to use a parameterized query, but you get
> the idea :-)
>
> Regards, Dave
>




view thread (6+ messages)  latest in thread

Message-ID: <20070613230611.mewiitg4mnco8kwo@imp3.uta.fi>
Permalink:  ../20070613230611.mewiitg4mnco8kwo@imp3.uta.fi/
Also on:    postgresql.org/message-id/20070613230611.mewiitg4mnco8kwo@imp3.uta.fi

 · 

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: Mihail.Mihailov@uta.fi, dpage@postgresql.org
  Subject: Re: php, postgresql and graphical images
  In-Reply-To: <20070613230611.mewiitg4mnco8kwo@imp3.uta.fi>
  References: <20070613115155.uykzmxtvxueoo4w8@imp3.uta.fi> <466FB441.6000204@postgresql.org> <20070613230611.mewiitg4mnco8kwo@imp3.uta.fi>

* 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