Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 1519A9FB771; Wed, 13 Jun 2007 17:06:24 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 67480-05; Wed, 13 Jun 2007 17:06:11 -0300 (ADT) X-Greylist: delayed 11:14:16.096598 by SQLgrey-1.7.4 X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from rehuapila.uta.fi (rehuapila.uta.fi [153.1.1.45]) by postgresql.org (Postfix) with ESMTP id 716759FB967; Wed, 13 Jun 2007 17:06:15 -0300 (ADT) Received: from valkoapila.uta.fi (valkoapila.uta.fi [153.1.1.42]) by rehuapila.uta.fi (8.13.8/8.13.8) with ESMTP id l5DK6D0s019589; Wed, 13 Jun 2007 23:06:13 +0300 (EEST) Received: from apila.uta.fi (localhost.localdomain [127.0.0.1]) by valkoapila.uta.fi (8.13.8/8.13.8) with ESMTP id l5DK6CrK020366; Wed, 13 Jun 2007 23:06:12 +0300 Received: from pippuri.uta.fi (pippuri.uta.fi [153.1.6.42]) by apila.uta.fi (8.13.8/8.13.8) with ESMTP id l5DK6CQK007400 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 13 Jun 2007 23:06:12 +0300 (EEST) Received: from pippuri.uta.fi (localhost.localdomain [127.0.0.1]) by pippuri.uta.fi (8.13.4/8.13.4/Debian-3sarge3) with ESMTP id l5DK6CoY001219; Wed, 13 Jun 2007 23:06:12 +0300 Received: (from wwwroot@localhost) by pippuri.uta.fi (8.13.4/8.13.4/Submit) id l5DK6BZ3001214; Wed, 13 Jun 2007 23:06:11 +0300 Received: from a81-197-58-174.elisa-laajakaista.fi (a81-197-58-174.elisa-laajakaista.fi [81.197.58.174]) by imp3.uta.fi (Horde MIME library) with HTTP; Wed, 13 Jun 2007 23:06:11 +0300 Message-ID: <20070613230611.mewiitg4mnco8kwo@imp3.uta.fi> Date: Wed, 13 Jun 2007 23:06:11 +0300 From: Mihail Mihailov To: Dave Page Cc: Mihail Mihailov , pgsql-php@postgresql.org Subject: Re: php, postgresql and graphical images References: <20070613115155.uykzmxtvxueoo4w8@imp3.uta.fi> <466FB441.6000204@postgresql.org> In-Reply-To: <466FB441.6000204@postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; DelSp="Yes"; format="flowed" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable User-Agent: Internet Messaging Program (IMP) H3 (4.1.5-cvs) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (apila.uta.fi [153.1.1.41]); Wed, 13 Jun 2007 23:06:12 +0300 (EEST) X-Scanned-By: MIMEDefang 2.62 on 153.1.1.42 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/6 X-Sequence-Number: 3808 Hi Dave and thanks for advice. You show in your example how to create an html file containing only =20 one picture. How do you insert multiple graphical images into a "mixed" document =20 containing text and graphical images? Do I still have to save bytea data into a temporary file (how?) and =20 than get in with tag? Sorry for stupid questions :-) Mike > >> Are there any other ways to export images from the database? > > Hi Mike, > > I store them in bytea columns, along with their mimetype, then use a > script like: > > > require "db.php"; > > $sql =3D "SELECT image_data, image_mimetype FROM images where id =3D " . > intval($_GET['id']); > > $res =3D pg_query($GLOBALS['db'], $sql); > > if (pg_numrows($res) !=3D 1) > { > header("HTTP/1.0 404 Not Found"); > exit(); > } > > $image =3D pg_unescape_bytea(pg_result($res, 0, 0)); > $mimetype =3D pg_result($res, 0, 1); > > header("Expires: " . date("D, j M Y H:i:s", time() + (86400)) . " UTC"); > header("Cache-Control: Public"); > header("Pragma: Public"); > > header("Content-Type: " . $mimetype); > echo $image; > > ?> > > I should really rewrite that to use a parameterized query, but you get > the idea :-) > > Regards, Dave >