开发者

Creating directories from filename?

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?


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


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.


How about using an uuid?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜