Search Postgresql Archives

Re: bytea / large object and image

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux