Note that there are some explanatory texts on larger screens.

plurals
  1. PObalanced file distribution structure
    primarykey
    data
    text
    <p>I have a server where archived files will be uploaded and stored. In order to improve performance of listing and checking file existance, I need to organzie the files in performance oriented directory structure.</p> <p>I have a database table that will hold the real name of the files and their temp name.</p> <pre><code>################################### FILES ################################### id int auto_increment primary key, name varchar (255), temp_name varchar (255) </code></pre> <p>The root directory can contain a max of 1000 subdrectories ranging from 0-999. Each of the directories will hold 1000 files. </p> <p>So the result will be </p> <pre><code>root/0 ==&gt; will hold file having the id range from 1-999 root/1 ==&gt; will hold file having the id range from 1000-1999 root/2 ==&gt; will hold file having the id range from 2000-1999 . . . root/999 ==&gt; will hold file having the id range from 999,000-999,999 </code></pre> <p>the directory where a file is stored can be found using the following equation</p> <pre><code>$directory = floor($file_id_from_db/1000); </code></pre> <p>WHERE $file_id_from_db is retrived from the files database table <code>files</code>.<code>id</code>.</p> <p>The problem takes place when 1,000,000th file is uplaoded then I have to start storing the files in a second level.</p> <p>I have to create a second level of directories ranging from 0 - 999 in the 0th directory root/0/0 - root/0/999</p> <p>then when I reach root/0/999 and I have placed 1000 files in it I need to move to root/1/999 and so on till I reach root/999/999.</p> <p>my current function looks something like that</p> <pre><code>function getPath($id){ $result = floor($file_id/1000); //Second level checks (Tried and crashed and burned) return "/$result"; } </code></pre> <p><strong>I have no idea how to implement the logic for creating the subdirectories?</strong></p> <p>Thank for any suggestions.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload