Page 1 of 1

images: blob or dirs?

Posted: Thu Feb 07, 2008 10:15 pm
by Dakke
New to PHP but here it goes:

I need to store images for this website. I thought to store all of it in the MySQL and use PHP to call those. I used blob, and tried to display the images, but for some reason I couldn't (forums suggested a header thing...).

But by browsing on forums, I found that lot of people suggest to store the images in dirs instead of mysql.

Ok, what's the best way to do so? Using mysql blob or dirs?

And are there any tutorials who can actually guide me in the coding of it?

Re: images: blob or dirs?

Posted: Thu Feb 07, 2008 10:40 pm
by Christopher
I would recommend storing image as files rather than in a database unless you have a very specific need. Filesystems are design for dealing with ... files. What was the reason you wanted to store them in the database?

Re: images: blob or dirs?

Posted: Thu Feb 07, 2008 11:09 pm
by Kieran Huggins
The rule of thumb is to store the file itself in the filesystem, and the metadata in the DB.

To avoid collisions, I usually store the file as the MD5 of their contents in one big directory. The original filename, the md5, the mime-type and all that other crap is stored in the DB.

When a file is requested you find it in the DB, send the headers based on the filename and mime-type, then readfile() the file from disk.