views:

63

answers:

4

Hi!

I'm creating website that handles "great amount" of images. I have decided to use multiple directories method for storing files eg. images/efg/ed/ehj/efgedehjokjvdf2jn4.jpg

I'm thinking that to prevent filename duplication is to take current timedate + some random string + md5 those = nice line of random string. Mostly I'm wondering method how to create those paths? What would be the best way to manage those? We are talking about 10,000 - 30,000 images for starter..

So if someone have nice tips or maybe share some code, that would be awesome! :) Oh yea, I'm using CodeIgniter for this project if that helps?

A: 

How about using an uuid?

villintehaspam
+1  A: 

Turn the first 4 hex characters of the hash into the first level of directories, and the second 4 hex characters into the second level. Store the file in there with the full hash.

Ignacio Vazquez-Abrams
dude check that my url example?
Marko
A: 

I'd use a uid for the pics themselves, but isn't there a limit of 32,000 files per directory? This would almost be exceeded immediately so you'd still need some directory structure.

Couldn't you make a new folder with the date they're uploaded and keep that in one database column and the uid in another -> you're not going to exceed 32,000 days of images.

niggles
+2  A: 

KISS:

date('Y')/date('md')/date('Hi')/md5($image).ext

It's pretty simple and I don't think you're going to exceed 32k files in any given minute.


If you don't need minutes and can work with a maximum of 8928 sub-directories you could just do:

date('Y')/date('mdH')/md5($image).ext
Alix Axel
better than my solution as I didn't think about adding 32K images per day - just the initial batch of them :-)
niggles