Skip site navigation (1) Skip section navigation (2)

Re: php, postgresql and graphical images

From: Dave Page <dpage(at)postgresql(dot)org>
To: Mihail Mihailov <Mihail(dot)Mihailov(at)uta(dot)fi>
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: php, postgresql and graphical images
Date: 2007-06-13 09:09:21
Message-ID: (view raw or whole thread)
Lists: pgsql-php
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:


require "db.php";

$sql = "SELECT image_data, image_mimetype FROM images where id = " .

$res = pg_query($GLOBALS['db'], $sql);

if (pg_numrows($res) != 1)
  header("HTTP/1.0 404 Not Found");

$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

In response to


pgsql-php by date

Next:From: Mihail MihailovDate: 2007-06-13 20:06:11
Subject: Re: php, postgresql and graphical images
Previous:From: Mihail MihailovDate: 2007-06-13 08:51:55
Subject: php, postgresql and graphical images

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group