title: How do you Store Millions of Images on your Server?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/446358/storing-a-large-number-of-images">Storing a large number of images</a>  </p>
  </blockquote>
  
  
  
  <p>Hello,</p>
  
  <p>I want to be able to scale to millions of user profile pics on my LAMP Server using PHP.</p>
  
  <p>I currently store all images in one folder, which is a big no-no, so I want to spread them out into many folders and sub-folders (e.g. aa/bb/ etc...).</p>
  
  <p>What is the best and most efficient way of doing that, especially if I do not want to have to call the DB to get the filename/path for that user's profile pic?</p>
  
  <p>I'm thinking of maybe doing a hash of the username and utilizing the first 4 letters of that hash to generate/locate the path for that user's profile pic, that way I wouldn't have to access anything additionally from the DB since I will always have the user's username. So, for example, if the first 4 characters of the user's username hash were "aabb", I would store that user's profile pic under aa/bb/username/profile.jpg , which should theoretically allow me to scale to millions of users without having to add anything to the DB, while spreading all the pics evenly throughout the aa/bb/ folder structure.</p>
  
  <p>Any ideas/input?</p>
  
  <p>Thanks! </p>