Re: bytea / large object and image

Поиск
Список
Период
Сортировка
От Tomas Vondra
Тема Re: bytea / large object and image
Дата
Msg-id 454CE0E5.2020200@fuzzy.cz
обсуждение исходный текст
Ответ на bytea / large object and image  ("Alain Roger" <raf.news@gmail.com>)
Список 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

В списке pgsql-general по дате отправления:

Предыдущее
От: "Raymond O'Donnell"
Дата:
Сообщение: Re: bytea / large object and image
Следующее
От: "SunWuKung"
Дата:
Сообщение: Re: Catch multiple records when doing Select Into