pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How do I display an image?
4+ messages / 3 participants
[nested] [flat]

* How do I display an image?
@ 2002-10-24 00:04  Patrick Hatcher <PHatcher@macys.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Patrick Hatcher @ 2002-10-24 00:04 UTC (permalink / raw)
  To: pgsql-php

Fairly new to PHP.  How do I display an image I have stored in my db?  I
found code on phpbuilder.com, but I must be doing something wrong. If I
just print out the field, it prints the machine code immediately.  But I
alas my users want an image instead of machine language.

CREATE TABLE mdc_imageref (
  keyp_imageref int4,
  modid int8,
  img bytea,
  keyf_image int4
)


$id = $_GET["id"];
if($id) {
     $db = db_connect();
     $result = pg_query($db,"Select ir.img,p.keyp_products
                    from mdc_products p join mdc_product_images pi on
p.keyp_products = pi.keyf_product
                    join mdc_attributes a on a.keyp_attribute =
pi.keyf_attribute
                    join mdc_images i on i.keyp_images = pi.keyf_image
                    join mdc_imageref ir on ir.keyf_image = i.keyp_images
                    where p.keyp_products = $id and keyp_attribute = 7");
         $row =  pg_fetch_array($result);
         $type = "JPG";
         Header( "Content-type:$type");
         echo $row[0];
}


TIA
Patrick Hatcher
Macys.Com
Legacy Integration Developer






^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: How do I display an image?
@ 2002-10-24 00:36  Cornelia Boenigk <poppcorn@cornelia-boenigk.de>
  0 siblings, 0 replies; 4+ messages in thread

From: Cornelia Boenigk @ 2002-10-24 00:36 UTC (permalink / raw)
  To: pgsql-php; Patrick Hatcher <PHatcher@macys.com>

Hi Patrick

Before storing the binary data in the BYTEA-Field use

pg_escape_bytea($imagedata)

After retrieving the imagedata from the table you must remove the slashes
the above function added. Use stripCslashes().

$image = stripcslashes($imagedata);

This works for me;-)
pg_escape_bytea() is available since php 4.2.0.

regards
Conni





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: How do I display an image?
@ 2002-10-24 12:46  Patrick Hatcher <PHatcher@macys.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Patrick Hatcher @ 2002-10-24 12:46 UTC (permalink / raw)
  To: Cornelia Boenigk <c@cornelia-boenigk.de>; +Cc: pgsql-php


that did it!  Thank you very much

Patrick Hatcher
Macys.Com
Legacy Integration Developer





                                                                                                                         
                    "Cornelia Boenigk"                                                                                   
                    <poppcorn@cornelia-b       To:     "PGSQL+PHP" <pgsql-php@postgresql.org>, "Patrick Hatcher"         
                    oenigk.de>                  <PHatcher@macys.com>                                                     
                                               cc:                                                                       
                    10/23/2002 05:36 PM        Subject:     Re: [PHP] How do I display an image?                         
                    Please respond to                                                                                    
                    "Cornelia Boenigk"                                                                                   
                                                                                                                         
                                                                                                                         




Hi Patrick

Before storing the binary data in the BYTEA-Field use

pg_escape_bytea($imagedata)

After retrieving the imagedata from the table you must remove the slashes
the above function added. Use stripCslashes().

$image = stripcslashes($imagedata);

This works for me;-)
pg_escape_bytea() is available since php 4.2.0.

regards
Conni









^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: How do I display an image?
@ 2002-10-27 22:28  knut.suebert@web.de
  parent: Patrick Hatcher <PHatcher@macys.com>
  0 siblings, 0 replies; 4+ messages in thread

From: knut.suebert@web.de @ 2002-10-27 22:28 UTC (permalink / raw)
  To: pgsql-php

Patrick Hatcher schrieb:

>          $row =  pg_fetch_array($result);
>          $type = "JPG";
>          Header( "Content-type:$type");
>          echo $row[0];

For most browsers that's enough, at least some versions of
InternetExplorer need more information:

   $data = $db->bytea_decode($db->f("data"));
   header(sprintf("Content-type: %s", $db->f("type")));
   header(sprintf("Content-Disposition: attachment; filename=%s",
                  $db->f("name")));
   header(sprintf("Content-length: %s", strlen($data)));
   print($data);



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2002-10-27 22:28 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-10-24 00:04 How do I display an image? Patrick Hatcher <PHatcher@macys.com>
2002-10-27 22:28 ` knut.suebert@web.de
2002-10-24 00:36 Re: How do I display an image? Cornelia Boenigk <poppcorn@cornelia-boenigk.de>
2002-10-24 12:46 Re: How do I display an image? Patrick Hatcher <PHatcher@macys.com>

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