I've read several questions about storing images in a database as opposed to folders on the server, and I've decided to go with folders, but I'm wondering how clever I need to be. I've found a lot of questions about storing thousands of images, but I just want to store three images per user (really one image in three flavors).
In this question the questioner first proposes a directory structure based on username (which in his case and in mine is an e-mail address). His directories would look something like:
/images/domain.com/user/imagename.png
Would that be ok to use in my case? I am not an old hand at this so I'm wondering if there's something I'm not thinking of in terms of security or performance that I should be concerned with. I'm hoping to keep all images in a folder outside the webroot, so I don't think there's an issue with users accessing files they aren't entitled to see, but are there other reasons why you might want to take a hash of the file and use it to generate the directory structure or use some other sort of pseudo-randomly generated gobbledegook instead of part of a username to generate directory structure?
Edit: I am using php and the photos are just profile photos if that makes any difference. They are basically visible to any user when searching for other users, so when it comes to security, I just don't want people to be able to hot link to a user's photo or to navigate to the photo directly by typing in a url that leads to it. That is unless, as I said, there are other security concerns I should be thinking about but don't know to think about.
I don't see why hashing the files would be of use unless you were expecting a good deal of them to be identical; then you could save lots of storage.
If users will ever be able to edit their usernames (and you can't tell the future!) then I wouldn't use that in the structure. Use a database primary key or something which will never change.
If you did want a bit more structure you could still split the ids across levels of structure, so for example: a user with an id 1234 would have images stored at:
/images/domain.com/12/34/imagename.png
Which would at least mean you didn't have more than a hundred directories when you look at the list...