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

Mihail Mihailov wrote:

> 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: <466FB441.6000204@postgresql.org>
Permalink:  ../466FB441.6000204@postgresql.org/
Also on:    postgresql.org/message-id/466FB441.6000204@postgresql.org

 · 

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

* 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