pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Load Image from File to Store in ByteA Field
6+ messages / 4 participants
[nested] [flat]

* Load Image from File to Store in ByteA Field
@ 2004-02-02 04:55  Muhyiddin A.M Hayat <middink@indo.net.id>
  0 siblings, 1 reply; 6+ messages in thread

From: Muhyiddin A.M Hayat @ 2004-02-02 04:55 UTC (permalink / raw)
  To: pgsql-php

How to Load Image from File to Store in ByteA Field?

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

* Re: Load Image from File to Store in ByteA Field
@ 2004-02-02 19:12  Cornelia Boenigk <poppcorn@cornelia-boenigk.de>
  parent: Muhyiddin A.M Hayat <middink@indo.net.id>
  0 siblings, 1 reply; 6+ messages in thread

From: Cornelia Boenigk @ 2004-02-02 19:12 UTC (permalink / raw)
  To: Muhyiddin A.M Hayat <middink@indo.net.id>; pgsql-php

Hi

> How to Load Image from File to Store in ByteA Field?
This is the way I store images with PHP. The column bild has the
datatype bytea.

function esc_bytea($imagedata) {
 $finde = array(chr(92), chr(0), chr(39));
 $ersetze = array('\\\134', '\\\000', '\\\047');
 $esc = str_replace($finde[0], $ersetze[0], $imagedata);
 $esc = str_replace($finde[1], $ersetze[1], $esc);
 $esc = str_replace($finde[2], $ersetze[2], $esc);
 return $esc;
}

     $fp = fopen($imagefile,"r");
     $contents = fread($fp, filesize($imagefile));
     fclose($fp);
     $esc_daten = esc_bytea($contents);

     $sql = "INSERT INTO byteatest (bild, name, size, typ, htmlstr) ";
     $sql .= "values ('$esc_daten', '$name', $size, '$typ',
'$htmlstr');";
     $res = @pg_exec($sql) or die ("Fehler bei der
Datenbankabfrage.");

Regards
Conni




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

* Re: Load Image from File to Store in ByteA Field
@ 2004-02-02 23:49  Paul & Natalie T <pntil@shentel.net>
  parent: Cornelia Boenigk <poppcorn@cornelia-boenigk.de>
  0 siblings, 2 replies; 6+ messages in thread

From: Paul & Natalie T @ 2004-02-02 23:49 UTC (permalink / raw)
  To: pgsql-php

Any modern version of PHP which has pg_ specific functions can do it 
like this:

    $string = pg_escape_bytea(file_get_contents($filename));
    pg_query("INSERT INTO TABLE pictures (picture_bytea) VALUES 
('$string');");

I prefer to use pg_escape() rather than code my own escape.

Paul

>Hi
>
>  
>
>>How to Load Image from File to Store in ByteA Field?
>>    
>>
>This is the way I store images with PHP. The column bild has the
>datatype bytea.
>
>function esc_bytea($imagedata) {
> $finde = array(chr(92), chr(0), chr(39));
> $ersetze = array('\\\134', '\\\000', '\\\047');
> $esc = str_replace($finde[0], $ersetze[0], $imagedata);
> $esc = str_replace($finde[1], $ersetze[1], $esc);
> $esc = str_replace($finde[2], $ersetze[2], $esc);
> return $esc;
>}
>
>     $fp = fopen($imagefile,"r");
>     $contents = fread($fp, filesize($imagefile));
>     fclose($fp);
>     $esc_daten = esc_bytea($contents);
>
>     $sql = "INSERT INTO byteatest (bild, name, size, typ, htmlstr) ";
>     $sql .= "values ('$esc_daten', '$name', $size, '$typ',
>'$htmlstr');";
>     $res = @pg_exec($sql) or die ("Fehler bei der
>Datenbankabfrage.");
>
>Regards
>Conni
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 8: explain analyze is your friend
>
>
>  
>





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

* Re: Load Image from File to Store in ByteA Field
@ 2004-02-03 01:09  Cornelia Boenigk <poppcorn@cornelia-boenigk.de>
  parent: Paul & Natalie T <pntil@shentel.net>
  1 sibling, 0 replies; 6+ messages in thread

From: Cornelia Boenigk @ 2004-02-03 01:09 UTC (permalink / raw)
  To: Paul & Natalie T <pntil@shentel.net>; pgsql-php

hi Paul

> Any modern version of PHP which has pg_ specific functions can do it
> like this:

You are 100% right.
My application had to run with PHP below 4.2 where pg_escape_bytea()
was not yet defined. And it works also with higher PHP versions ;-)

Conni





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

* Re: Load Image from File to Store in ByteA Field
@ 2004-02-03 09:19  Muhyiddin A.M Hayat <middink@indo.net.id>
  parent: Paul & Natalie T <pntil@shentel.net>
  1 sibling, 1 reply; 6+ messages in thread

From: Muhyiddin A.M Hayat @ 2004-02-03 09:19 UTC (permalink / raw)
  To: Paul & Natalie T <pntil@shentel.net>; pgsql-php

How big file size do I stored in ByteA Field.



----- Original Message ----- 
From: "Paul & Natalie T" <pntil@shentel.net>
To: <pgsql-php@postgresql.org>
Sent: Tuesday, February 03, 2004 7:49 AM
Subject: Re: [PHP] Load Image from File to Store in ByteA Field


> Any modern version of PHP which has pg_ specific functions can do it 
> like this:
> 
>     $string = pg_escape_bytea(file_get_contents($filename));
>     pg_query("INSERT INTO TABLE pictures (picture_bytea) VALUES 
> ('$string');");
> 
> I prefer to use pg_escape() rather than code my own escape.
> 
> Paul
> 
> >Hi
> >
> >  
> >
> >>How to Load Image from File to Store in ByteA Field?
> >>    
> >>
> >This is the way I store images with PHP. The column bild has the
> >datatype bytea.
> >
> >function esc_bytea($imagedata) {
> > $finde = array(chr(92), chr(0), chr(39));
> > $ersetze = array('\\\134', '\\\000', '\\\047');
> > $esc = str_replace($finde[0], $ersetze[0], $imagedata);
> > $esc = str_replace($finde[1], $ersetze[1], $esc);
> > $esc = str_replace($finde[2], $ersetze[2], $esc);
> > return $esc;
> >}
> >
> >     $fp = fopen($imagefile,"r");
> >     $contents = fread($fp, filesize($imagefile));
> >     fclose($fp);
> >     $esc_daten = esc_bytea($contents);
> >
> >     $sql = "INSERT INTO byteatest (bild, name, size, typ, htmlstr) ";
> >     $sql .= "values ('$esc_daten', '$name', $size, '$typ',
> >'$htmlstr');";
> >     $res = @pg_exec($sql) or die ("Fehler bei der
> >Datenbankabfrage.");
> >
> >Regards
> >Conni
> >
> >
> >---------------------------(end of broadcast)---------------------------
> >TIP 8: explain analyze is your friend
> >
> >
> >  
> >
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
> 




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

* Re: Load Image from File to Store in ByteA Field
@ 2004-02-03 16:21  scott.marlowe <scott.marlowe@ihs.com>
  parent: Muhyiddin A.M Hayat <middink@indo.net.id>
  0 siblings, 0 replies; 6+ messages in thread

From: scott.marlowe @ 2004-02-03 16:21 UTC (permalink / raw)
  To: Muhyiddin A.M Hayat <middink@indo.net.id>; +Cc: Paul & Natalie T <pntil@shentel.net>; pgsql-php

Up to about 1 gig (theoretically 2 gig max but encoding might take up some 
space.)

On Tue, 3 Feb 2004, Muhyiddin A.M Hayat wrote:

> How big file size do I stored in ByteA Field.
> 




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


end of thread, other threads:[~2004-02-03 16:21 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-02-02 04:55 Load Image from File to Store in ByteA Field Muhyiddin A.M Hayat <middink@indo.net.id>
2004-02-02 19:12 ` Cornelia Boenigk <poppcorn@cornelia-boenigk.de>
2004-02-02 23:49   ` Paul & Natalie T <pntil@shentel.net>
2004-02-03 01:09     ` Cornelia Boenigk <poppcorn@cornelia-boenigk.de>
2004-02-03 09:19     ` Muhyiddin A.M Hayat <middink@indo.net.id>
2004-02-03 16:21       ` scott.marlowe <scott.marlowe@ihs.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