images: blob or dirs?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dakke
Forum Newbie
Posts: 24
Joined: Fri Aug 10, 2007 6:34 pm

images: blob or dirs?

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: images: blob or dirs?

Post 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?
(#10850)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: images: blob or dirs?

Post 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.
Post Reply