how to retrieve pictures from postgreSQL DB
| From: | Alain Roger | Date: | Sun, 25 Feb 2007 19:31:48 +0000 |
| Subject: | how to retrieve pictures from postgreSQL DB | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-249405@lists.php.net to get a copy of this message | ||
Hi,
I previously sent email about process how to retrieve and save pictures in
postgreSQL DB.
Now i know how to save them in DB, however i would like to know how can i
retrieve the pictures and display them without knowing the picture extension
?
i mean that in my DB i have GIFs, JPGs pictures.
1. My following code display without problem JPEG picture but what about GIF
?
2. How can i display picture without using ==> header('Content-type:
image/jpeg'); Because this must be before displaying pictures.
3. what should i do if i want to display several types of pictures in the
PHP page ?
My code :
<?php
$dbconn = pg_connect($conn_string) or die('Could not connect: ' .
pg_last_error());
$res = pg_query("SELECT * FROM immense.photo where photo_id=20");
$raw = pg_fetch_result($res, 'photo_image');
if (!$res)
{
echo "An error occured.\n";
exit;
}
else
{
header('Content-type: image/jpeg');
echo pg_unescape_bytea($raw);
}
// Closing connection
pg_close($dbconn);
?>
--
Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.1.4
Apache 2.0.58
PHP 5