按日期在服务器 - 子文件夹上存储大量文件?

I want to separate images stored on server in multiple folders. I'm thinking to create this structure /images/year/month (images/2011/04). Files names are stored in the database and also create date. Is this a good idea for separate files?

Well, it depends, in part, in what you want to do with them, and what you consider to be a large number.

As with indexing columns in a database, this scheme may benefit some operations and be detrimental to others.

For example, in a simple scheme that didn't have th date available, being able to find an image based on part of its name could end up being a little more difficult since you would have no idea where it would be. I've used this scheme for things like log files but that works well since I already knew where it will be:

/logs/2011/01/2011_01_14.log

and didn't have to go searching for it.

Now you've solved that particular problem since your database entry holds the date as well so I can't see any immediate problems with your scheme. That's not to say there isn't any :-)

My advice would be to do the simplest thing (flat directory format) initially and only worry about it when it becomes a problem. Since you have the dates, it would be a simple matter to move all images, based on that, to separate directories.

Of course, if you've already implemented separate directories, stick with that. Again, it should hopefully be relatively easy to adjust in future if the method is flawed.

One thing you may want to consider is storing the location (absolute, or relative to a known point) in the database as well, rather than just the date. Then you would use that (rather than an operation on the date) to locate the file.

This would allow you to totally change the method used for placing files without having to change any of the code that located them.

That sounds ok. I ran a photo startup for about 5 years and used a similar structure for storing the photos. It should scale moderately well (we had ≈1M photos). I would also look at storing a sha1 or md5 hash of the image so you can easily detect duplicates and make sure that you normalize the name of the file before persisting it to disk.