Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8467601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:41:35+00:00 2026-06-10T15:41:35+00:00

I have a server where archived files will be uploaded and stored. In order

  • 0

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.

I have a database table that will hold the real name of the files and their temp name.

###################################
FILES
###################################
id int auto_increment primary key,
name varchar (255),
temp_name varchar (255)

The root directory can contain a max of 1000 subdrectories ranging from 0-999. Each of the directories will hold 1000 files.

So the result will be

root/0 ==> will hold file having the id range from 1-999
root/1 ==> will hold file having the id range from 1000-1999
root/2 ==> will hold file having the id range from 2000-1999
.
.
.
root/999 ==> will hold file having the id range from 999,000-999,999

the directory where a file is stored can be found using the following equation

$directory = floor($file_id_from_db/1000);

WHERE $file_id_from_db is retrived from the files database table files.id.

The problem takes place when 1,000,000th file is uplaoded then I have to start storing the files in a second level.

I have to create a second level of directories ranging from 0 – 999 in the 0th directory
root/0/0 – root/0/999

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.

my current function looks something like that

function getPath($id){    
     $result = floor($file_id/1000);
     //Second level checks (Tried and crashed and burned)
     return "/$result"; 
}

I have no idea how to implement the logic for creating the subdirectories?

Thank for any suggestions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:41:36+00:00Added an answer on June 10, 2026 at 3:41 pm

    If another approach is possible you can try the following:

    • pad the db-id to e.g. 20 places (something that will suffice for the long run) like: 00000000000001665765
    • split that string into chunks of suitalbe lenghts (e.g. 2) and rejoin those with your DIRECTORY_SEPARATOR

    This will then be your storage path, e.g.:

    $id = 1665765;
    $paddedId = str_pad($id, 20, '0', STR_PAD_LEFT);
    
    echo $path = '/' . implode(DIRECTORY_SEPARATOR, str_split($paddedId, 2));
    
    // ==> /00/00/00/00/00/00/01/66/57/65
    

    this way, you’ll have at most 100 directories/files per directory. (this will of course be different if you choose another split-length)

    To easily create the directory you can use the third parameter for mkdir.

    mkdir(dirname($path), 0755, true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that is playing archived *.mov files from a server. Some
Our Windows file server has an archive service installed that stubs files that have
I have several files out on a server which my user downloads into their
I have a client-server Silverlight application, which is use Socets. I have server appliaction
I'm working within a platform that I do not have server side access to
My server have default php version of 4, so when I run some script
I have a server in my network for which I want to DROP outbound
I have a server with 2 connections SOCKET which is connected with clients and
I have SQL Server 2005 and I am looking for a way to take
I have a server application that is compiled in 32 bit, and I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.