What is the best way to organize folders for future scaling? I'm in progress to launch a new website. I expect that in the future I will have to deal with storage capacity of uploaded photos, respectively I will have to distribute them on multiple hard drivers. Currently I use something like this:

/1/1/photo.jpg /1/2/photo.jpg . /10/10/photo.jpg


I use part of a file hash as a file name (and store the hash in the database), then organize them into subdirectories based on the first letter (or letters). For example, file de9f2c7fd25e1b3afad3e85a.jpg goes to


Since hashes are evenly distributed it's easy to split the store to multiple drives, every directory should have about the same number of images. Currently, I have about 2TB worth of images organized like this, and it works like a charm.

Btw, one neat thing about this is if you somehow mess up your filenames, you won't have gazillion of images unorganized, just hash them and you're back to business.

  • i use something like /storage/de/9f/de9f2c7fd25e1b3afad3e85a.jpg -- figure that a 2-level, 256-branching tree (65536 dirs max) will keep the # of files per dir at a reasonable level. – Jason S Nov 9 '09 at 0:47

Unique timestamped URLs would be a good start, f.e. 2009/11/30/photo-widthxheight-{other extracted EXIF information}.jpg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy