Re: bytea / large object and image

From: Tomas Vondra <tv(at)fuzzy(dot)cz>
To: pgsql-general(at)postgresql(dot)org
Cc: Alain Roger <raf(dot)news(at)gmail(dot)com>
Subject: Re: bytea / large object and image
Date: 2006-11-04 18:50:13
Message-ID: 454CE0E5.2020200@fuzzy.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Hi,
>
> I create a table with some large object (ref: OID) to store some images.
> When my PHP will display some data, it will also display the images
> stored as OID.
>
> However, i've read that before i must restore the image by exporting
> them to local (on server) file.

I'm not sure what you mean by 'exporting to local file'. You don't have
to store each image in a separate file, you can store them in a bytea
column, use a script to load the data and send them to the client.

The point is you can't write them with the other data (HTML tags, text
etc) as the browsers handle images as separate objects using the <img>
tag. So all you have to do is basically something like this

<?php

// load the image data from the database
$sql = 'SELECT image_data FROM images WHERE id = ' . $id;
... do the SQL

// send them to the client
head('Content-type: image/png'); // set the correct mime-type
echo $imageData;

?>

That's all.

> isn't it easier in this case, to simply store the path and file name of
> file to DB and just read the data to display image on PHP pages ?
> what is the purpose in this case to store image a bytea / large object ?

This is true in case of 'dumb' databases as for example MySQL, as these
databases handle LOB columns pretty bad.

Tomas

In response to

Browse pgsql-general by date

  From Date Subject
Next Message SunWuKung 2006-11-04 20:04:30 Re: Catch multiple records when doing Select Into
Previous Message Joshua D. Drake 2006-11-04 18:43:07 Re: bytea / large object and image