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

Re: php, postgresql and graphical images

From: Mihail Mihailov <Mihail(dot)Mihailov(at)uta(dot)fi>
To: Dave Page <dpage(at)postgresql(dot)org>
Cc: Mihail Mihailov <Mihail(dot)Mihailov(at)uta(dot)fi>, pgsql-php(at)postgresql(dot)org
Subject: Re: php, postgresql and graphical images
Date: 2007-06-13 20:06:11
Message-ID: 20070613230611.mewiitg4mnco8kwo@imp3.uta.fi (view raw or flat)
Thread:
Lists: pgsql-php
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
>


In response to

Responses

pgsql-php by date

Next:From: Dave PageDate: 2007-06-13 20:39:55
Subject: Re: php, postgresql and graphical images
Previous:From: Dave PageDate: 2007-06-13 09:09:21
Subject: Re: php, postgresql and graphical images

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