X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 3BC4DD1D313 for ; Tue, 3 Feb 2004 09:50:39 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 32310-09 for ; Tue, 3 Feb 2004 05:50:30 -0400 (AST) Received: from smtp-1.indo.net.id (smtp-1.indo.net.id [202.159.32.91]) by svr1.postgresql.org (Postfix) with SMTP id 8EDBCD1D501 for ; Tue, 3 Feb 2004 05:50:22 -0400 (AST) Received: (qmail 16229 invoked from network); 3 Feb 2004 16:29:32 +0700 Received: from smtp.indo.net.id (202.159.32.81) by smtp-1.indo.net.id with SMTP; 3 Feb 2004 16:29:32 +0700 Received: (qmail 27147 invoked from network); 3 Feb 2004 16:29:31 +0700 Received: from unknown (HELO smtp.surabaya.indo.net.id) (202.159.51.117) by smtp.indo.net.id with SMTP; 3 Feb 2004 16:29:31 +0700 Received: from smtp [202.159.51.117] by smtp.surabaya.indo.net.id (SMTPD32-7.10) id AF1629E00E8; Tue, 03 Feb 2004 15:43:02 +0700 Received: FROM MIDDINKS BY smtp ; Tue Feb 03 15:42:58 2004 +0700 Message-ID: <00be01c3ea38$247b62c0$4f00a8c0@MIDDINKS> From: "Muhyiddin A.M Hayat" To: "Paul & Natalie T" , References: <003c01c3e948$ee2bc970$4f00a8c0@MIDDINKS> <00c101c3e9c0$79373640$0201a8c0@zwerg2000> <401EE1F0.2030106@shentel.net> Subject: Re: Load Image from File to Store in ByteA Field Date: Tue, 3 Feb 2004 17:19:32 +0800 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/14 X-Sequence-Number: 2562 How big file size do I stored in ByteA Field. ----- Original Message ----- From: "Paul & Natalie T" To: 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 >