title: Creating algorithm for File system structure for auto-incremented images
body: <p>I have nearly 1 million photos auto-incremented starting at "1".</p>
  
  <p>So, I have the following:</p>
  
  <pre><code>1.jpg
  2.jpg
  3.jpg
  4.jpg
  5.jpg
  ....
  1000000.jpg
  </code></pre>
  
  <p>Currently, I have all of these files in a single Ext4 linux directory.</p>
  
  <p>As you can imagine, the filesystem is crazy slow.</p>
  
  <p>Using PHP, how can I create an algorithm that divides up my images into a directory structure so that each directly has significantly less objects per directory.</p>
  
  <p>For example:</p>
  
  <pre><code>1000/1.jpg
  1000/2.jpg
  1000/3.jpg
  ...
  1000/999.jpg
  1000/1000.jpg
  2000/1001.jpg
  2000/1002.jpg
  2000/1003.jpg
  2000/1999.jpg
  </code></pre>
  
  <p>How would I divide/modulus/implode/shift the image name (id) into a file structure like such above?</p>
  
  <p><strong>UPDATE</strong>:</p>
  
  <p>Basically, I want to create a PHP function that does the following.</p>
  
  <ul>
  <li>Only accept positive integers, not including 0.</li>
  <li>For values 1-999, return 0</li>
  <li>For values 1000-1999, return 1000</li>
  <li>For values 10,000-10,999, return 10000</li>
  <li>For values 25,000-25,999, return 25000</li>
  </ul>