I am making a website which allows users to upload images for their profiles. I would like to know which of these would be the better route to take (The file names in all these cases would be a randomly generated string):
-
Have all the files be saves in a single folder called uploads
-
Create a folder named after the numeric user id of the user and place all of their images in their own folder. Each time they upload a new image I would check to see (using PHP) if the folder named after their id exists and if so not make a new dir and just put the images in the existent one
-
Same as #2 but don’t check to see if a folder exists named after the user id, PHP or Linux seems to know not to make one if one already exists and use the one that does.
-
Something better
So which would these would be better from a performance perspective. I am really concerned about speed here. If I have hundreds of thousands of images all in one folder it seems like retrieving one among many would take quite some time. And I’m not sure if organizing them into sub folders would make things better.
I use the following structure:
Looks like others also find this way a good way.