Re: php, postgresql and graphical images - Mailing list pgsql-php

From Dave Page
Subject Re: php, postgresql and graphical images
Date
Msg-id 466FB441.6000204@postgresql.org
Whole thread Raw
In response to php, postgresql and graphical images  (Mihail Mihailov <Mihail.Mihailov@uta.fi>)
Responses Re: php, postgresql and graphical images  (Mihail Mihailov <Mihail.Mihailov@uta.fi>)
List 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:

<?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

pgsql-php by date:

Previous
From: Mihail Mihailov
Date:
Subject: php, postgresql and graphical images
Next
From: Mihail Mihailov
Date:
Subject: Re: php, postgresql and graphical images