Hi Wade,

Regarding storing images as files or in a BLOB...

...I definitely would store them as files.

Performance may be a bit better as blobs than when storing them in files
(although that depends, if you have to make thumbnails 'on the fly' it may
be slower again than just retrieving a stored thumbnail), but if you store
them as BLOBS in your database, the size of the database may quickly run out
of hand. And in the first place make regularly backing up of your database
content inviable.
Whereas keeping them as files keeps the DB small enaling regular backing up.

Regarding Gurudattas answer...

> I seriously doubt if image from stored in DB will be faster,
> since u will have to
>
> 1) search it in Db
A search will have to be done in the DB anyway, just to come up with the
filename for instance...

> 2) retrieve it from Db in memory
Memory access is generally faster than disk acces, which is why a blob
generally is considered advantageous.

> 3) Save it by creating a new file
Just like you don't need let PHP save an HTML file first to have the user
access it, it is not needed to save the image first. The image can be sent
'on the fly', just like a PHP generated HTML page is sent.

> 4) Create code to send this file to user
You will have to create that code (well, just a formatted <IMG SRC="...">
tag) anyway to make the browser understand there is an image to be
displayed.

> 5) U will have to do this for each user every time
Yep, same with an image read from file.

> 6) Hence it wont be in users cache
Hmmm, why wouldn't it be cached? PH generated documets get caced as well,
why wouldn't an image be cached? To the browser it doesn't matter to much
from where the 1's and 0's were pulled that make the image.

As far as I understood it is better, performance wise, to store images in a
DB (although I wonder if that still holds if you routinely have to generate
thumbnails on the fly) but for general manageability of a site, especially
when large numbers of images are required, storing them as files keeps
things more organised.
I always store images as files, with a name derived from the tablename,
underscore, value of the primary key, underscore, number of the field
containing the filename (that way avoiding naming conflicts is a row
contains more than one fieldcontaining a filename).

But well, every solutin always has pros and cons, generally there is more
than one 'right' way to solve a problem. How 'right' a solution is depends
on the weight one gives to each argument.

Marc

Reply via email to