Best way to manage photos

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
User avatar
arpowers
Forum Commoner
Posts: 76
Joined: Sun Oct 14, 2007 10:05 pm
Location: san diego, ca

Best way to manage photos

Post by arpowers »

Hey guys,
What is the best method of managing photos with a php/mysql application??

I've done a little looking around and it seems like some use a database and other use directories...

can anybody straighten me out?
Thanks!
:P
Andrew[/s]
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Best way to manage photos

Post by califdon »

arpowers wrote:Hey guys,
What is the best method of managing photos with a php/mysql application??

I've done a little looking around and it seems like some use a database and other use directories...

can anybody straighten me out?
Thanks!
:P
Andrew[/s]
You don't need straightening out (as far as I know), it's just that there is no single or simple answer to your question. There are two options: store images as blobs in a table, and store path/filename pointers to wherever the images are stored as files.

If you have very large numbers of very large images, storing them in a table might cause a performance problem. If you store them as files, problems can arise from the files or their paths being changed or the files can be deleted without updating the table. So your choice will depend on the relative importance of such factors. That's why some use one option and others use another option.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

I think more often than not, you're going to hear the same thing from experienced developers - keep the files in the filesystem. The performance gain is huge. I had one photo repository system that started out using the database as the storage medium. It had about 900 100x100 images (not very large). The second version used the filesystem & was about 2-3x faster than the database version. Development was marginally more complex, but very worth it.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Inkyskin
Forum Contributor
Posts: 282
Joined: Mon Nov 19, 2007 10:15 am
Location: UK

Post by Inkyskin »

Yeah, I hate storing images in a database. OpenAds does this by default, and it's hell.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post by Mordred »

With huge amounts of images, consider putting them in a wide tree of subdirectories, or you'll run into the limits of the underlying file system.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

@mordred - not really. At least from what I've noticed. On a freebsd platform I easily had over 100,000 images. Performance was no problem. The problem came when opening the folder and reading the contents. Plus, by default, most ftp clients only like to read 2000 file entries. I backed up my site on a windows drive, and php had no problems accessing the images directly, but opening the folder was hellacious. I don't know how this would scale if the images were into the million+ count, but I wouldn't see a reason for problems.

However, it's suggested that you organize your image file system as much as possible.

IE.

images/
images/full/
images/thumbs/
images/full/user/
images/thumbs/user/

Or use the date instead of user.. something that's easily navigable and relatively easy to determine what's inside the folder.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Windows generally (at least in older, than Vista, versions) had performance drops at multiples of 500 items per folder or something. Systems which are accessed heavily should be split apart too, to help performance.
yanglei1979
Forum Commoner
Posts: 38
Joined: Sat Aug 25, 2007 10:21 pm

Post by yanglei1979 »

very easy.

I have been developing such a system.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

y'all know I like to store data as the md5 of it's contents. If I have a system where there will be more than a few thousand files I store in alphabetical directories based on he first so many characters, like so:

Code: Select all

0/a/a/0aa1ea9a5a04b78d4581dd6d17742627
1/9/6/196b0f14eba66e10fba74dbf9e99c22f
b/5/b/b5b037a78522671b89a2c1b21d9b80c6
Post Reply