Re: How to insert an image into Postgres's database using PHP?
| From: | fabrizio dot ermini at sysdat dot it | Date: | Wed, 09 Aug 2000 12:24:37 +0000 |
| Subject: | Re: How to insert an image into Postgres's database using PHP? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-1899@lists.php.net to get a copy of this message | ||
> If anyone here knows how to do this, please help me too... can anyone send
> php examples about insert a file into a postgressql database using a form,
> and how can I retrieve this file.
>
> Hi,
>
> I unsuccessfully trying insert gif into Postgres's database.
> Does anyone help me, please?
>
In response to both: insertion of binary objects (GIFs, generic files
ecc.) in postgreSQL is possible using BLOB (Binary Large
Objects), or "Inversion Large Objects" as they are called in some
part of Postgres Manual.
As for how to use Large Objects in Postgres, I can say only this:
DON'T.
You won't have any benefit in storing GIFs or other file directly into
Postgres Data structures, and in exchange you will render your life
much harder and you will slow tremendously your DBMS.
DBMS are good for storing structured data. If you need to park
somewhere generic binary files, use ol'good filesystem.
That is: let's suppose you've setup a form that puts up some files
using the HTTP upload techique (it's explained in PHP manual very
clearly). In your scripts, you will have the file saved in a temp
location, and a variabile containing the name of the file.
All you have to do is just copy the file in some "special" dir,
preferably out of the web tree (unless the file is a Gif or other image
that must be linked to a HTML page), possibly renaming it in some
clever way (i.e.: if the file is the picture representing an item of a
catalog, you could insert directly in the filename the ID of that item,
such as "img_itemID_picturename.gif"), and then store in the DB
JUST THE PATH of the file you've just saved, along with all the
information you need to index the file (i.e. the name of the image,
the article the file is referring, the name of the HTML page that
must include that file, the works...).
This way, if you need to retrieve that file, you can use the DB
capabilities to search it by looking for its extra info, and than use
the info stored in the DB to get to the file using PHP's filesystem
functions.
I hope I've been clear enough.
bye!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Fabrizio Ermini Alternate E-mail:
C.so Umberto, 7 faermini@tin.it
loc. Meleto Valdarno Mail on GSM: (keep it short!)
52020 Cavriglia (AR) faermini@sms.tin.it