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 04688D1B45B for ; Mon, 2 Feb 2004 23:49:27 +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 52191-06 for ; Mon, 2 Feb 2004 19:49:26 -0400 (AST) Received: from seahorse.shentel.net (seahorse.shentel.net [204.111.11.44]) by svr1.postgresql.org (Postfix) with ESMTP id 14DF4D1C915 for ; Mon, 2 Feb 2004 19:49:23 -0400 (AST) Received: from shentel.net (ha96s373.d.shentel.net [204.111.97.117]) by seahorse.shentel.net (8.11.7/8.11.7) with ESMTP id i12NnH429746 for ; Mon, 2 Feb 2004 18:49:17 -0500 Message-ID: <401EE1F0.2030106@shentel.net> Date: Mon, 02 Feb 2004 18:49:04 -0500 From: Paul & Natalie T User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-php@postgresql.org Subject: Re: Load Image from File to Store in ByteA Field References: <003c01c3e948$ee2bc970$4f00a8c0@MIDDINKS> <00c101c3e9c0$79373640$0201a8c0@zwerg2000> In-Reply-To: <00c101c3e9c0$79373640$0201a8c0@zwerg2000> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/9 X-Sequence-Number: 2557 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 > > > >