Re: Load Image from File to Store in ByteA Field

Lists: pgsql-php
From: "Muhyiddin A(dot)M Hayat" <middink(at)indo(dot)net(dot)id>
To: <pgsql-php(at)postgresql(dot)org>
Subject: Load Image from File to Store in ByteA Field
Date: 2004-02-02 04:55:27
Message-ID: 003c01c3e948$ee2bc970$4f00a8c0@MIDDINKS
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-php

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


From: "Cornelia Boenigk" <poppcorn(at)cornelia-boenigk(dot)de>
To: "Muhyiddin A(dot)M Hayat" <middink(at)indo(dot)net(dot)id>, "PGSQL+PHP" <pgsql-php(at)postgresql(dot)org>
Subject: Re: Load Image from File to Store in ByteA Field
Date: 2004-02-02 19:12:08
Message-ID: 00c101c3e9c0$79373640$0201a8c0@zwerg2000
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: 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


From: Paul & Natalie T <pntil(at)shentel(dot)net>
To: pgsql-php(at)postgresql(dot)org
Subject: Re: Load Image from File to Store in ByteA Field
Date: 2004-02-02 23:49:04
Message-ID: 401EE1F0.2030106@shentel.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: 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
>
>
>
>


From: "Cornelia Boenigk" <poppcorn(at)cornelia-boenigk(dot)de>
To: "Paul & Natalie T" <pntil(at)shentel(dot)net>, <pgsql-php(at)postgresql(dot)org>
Subject: Re: Load Image from File to Store in ByteA Field
Date: 2004-02-03 01:09:04
Message-ID: 00fc01c3e9f2$936f05b0$0201a8c0@zwerg2000
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: 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


From: "Muhyiddin A(dot)M Hayat" <middink(at)indo(dot)net(dot)id>
To: "Paul & Natalie T" <pntil(at)shentel(dot)net>, <pgsql-php(at)postgresql(dot)org>
Subject: Re: Load Image from File to Store in ByteA Field
Date: 2004-02-03 09:19:32
Message-ID: 00be01c3ea38$247b62c0$4f00a8c0@MIDDINKS
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-php

How big file size do I stored in ByteA Field.

----- Original Message -----
From: "Paul & Natalie T" <pntil(at)shentel(dot)net>
To: <pgsql-php(at)postgresql(dot)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
>


From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: "Muhyiddin A(dot)M Hayat" <middink(at)indo(dot)net(dot)id>
Cc: Paul & Natalie T <pntil(at)shentel(dot)net>, <pgsql-php(at)postgresql(dot)org>
Subject: Re: Load Image from File to Store in ByteA Field
Date: 2004-02-03 16:21:16
Message-ID: Pine.LNX.4.33.0402030920510.23444-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: 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.
>