Re: 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
Thread:
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

In response to

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Gustavo Paixao 2004-02-02 23:29:57 PG_CONNECT error
Previous Message Muhyiddin A.M Hayat 2004-02-02 04:55:27 Load Image from File to Store in ByteA Field