Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Storing a million images in the filesystem

I am designing a website which will potentially have millions of images. Whats the best way to arrange them..All of the images are uploaded by some users. I am thinking of creating a folder structure with their user id and put the image in it..Does it make any server maximum number of folders or server performance..Please let me know if you can think of some best architecture...?

Another way I am thinking was: create folder from a to z and inside I will create user's folder and keep the images

Thank you for your valuable suggestion

I will use Linux file system..php to upload files, gd2 to resize images.

share|improve this question

marked as duplicate by Evan Anderson, Kyle Brandt Aug 2 '10 at 23:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Are you expecting millions of users uploading a few images or a few users uploading millions of images? Are you wanting to keep the filename the users upload with? Could these result in duplicate filenames? Could you offload this work to Amazon S3 or Rackspace Cloud Files? – kaerast Aug 2 '10 at 22:45

Honestly, the way you arrange them should depend on what exactly you are doing with the pictures. Do you want them organized by user, or do you want them in a pool. How are you presenting the images. Also, how are you going to name the images? You could certainly do what you are asking about, though I wonder about the necessity of the extra level of a-z folders. That seems like a bit of unnecessary depth. You could also honestly put them all in one folder together and use UUIDs to name the pictures to ensure you don't have name collisions. Depending on how you want to manage them, you'll probably want to keep a database of the pictures to allow ease of access. If you provide more details on what you are wanting to do, we can provide more useful suggestions.

share|improve this answer
Most filesystems will have trouble with 1M files in one directory. 1000 files should be fine, 10k is already pushing it with some. Other than that, it's an organization issue, and the answer is bound to be extremely situation-specific. – Gilles Aug 2 '10 at 22:06
Ext3/4 and XFS shouldn't have any trouble with it. Theoretically, Ext2 can handle 10^20 files in a directory – Tristan Aug 2 '10 at 22:17
You can't have more files than inodes, and you'll hit that limit a long time before you hit 10^20. Ext2 performance is horrible when you've got thousands of files in a directory. Ext3 has the dir_index option which will store directories in trees for significantly improved performance. – gbroiles Aug 3 '10 at 5:34