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 8677613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:30:17+00:00 2026-06-12T20:30:17+00:00

I am creating a database application that (among many other things) allows users to

  • 0

I am creating a database application that (among many other things) allows users to upload and download files. The files are stored on a file server and I have set up an Apache HTTP server with PHP scripts to process (i.e. upload and download) the files. The database only stores a link to the file and not the file itself. My question is this: How should I organize the files on my file server?

Currently, I am creating a directory structure based on the current date and I rename the files with an MD5 hash of the current date/time (including milliseconds) plus some random characters (i.e. I’m adding “salt”):

\\yyyy\mm\dd\debb40da158040e4f3b93f9576840c07

This (above) is the link that is stored in the database (of course, I also store the real file name in the database so that I can rename the file when the user goes to download it—the user never sees the actual link).

I use yyyy\mm\dd for the directory structure to avoid performance issues (I’m told that a lot of files in the same directory can slow things down) and I rename the files with a unique string to avoid clashes when users upload files with the same name.

I’d like to get other opinions on the best way to deal with storing files in this kind of situation. I’ve seen some developers keep the file name, but append (as a prefix) the database ID of the corresponding row in the file information table—I see some advantages to this approach since the file names are “human readable” and you can figure out what the files are if the database file information table ever got corrupted or deleted.

  • 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-12T20:30:19+00:00Added an answer on June 12, 2026 at 8:30 pm

    How about having a structure utilising timestamp(upload date) as the 1st level directory, md5 hash of the file contents as the 2nd level(hash of file contents ensures the file is unique/name independent), upload timestamp as the 3rd(enables you to have different versions of the same file uploaded at different times), and the file with it’s actual filename in the 4th level. e.g. <date timestamp>/<md5 of file contents>/<timestamp>/<filename>

    This way your dir structure will have information on:

    • list of files uploaded on a particular date
    • unique files independent of their filenames
    • versioning
    • maintain the filename without the need to change it on the fly

    The handicap with the file contents md5 hash is that if you have significantly large files there’s going to be a slight overhead in generating.

    FURTHER IDEAS

    • you can break the date in as your previous format (yyyy/mm/dd or even just yyyy/date) if this is a system with many users that upload files every day and is certain to create 365 dirs for each day of the year, although performance is degraded when you have a list of entries greater than 10k in a dir(and in a server based OS greater than 100k up to a few millions), so that should give you about 25-30 years before noticing any degradation if you go with just a single date dir.

    • the hash of file contents is the way to go to guarantee filename independency I believe, and although it will add a small overhead to calculate the md5 of the contents it is a trivial one compared to the uploading time. E.g. a 100 mb file will take an x amount of time to upload depending on connection speed, after it is uploaded you just calculate the file contents on the fly using md5sum which will add just a few seconds(5-6 for a 100 mb file) to the upload time as the user will perceive it.

    • you can further use the md5 of the file contents(assuming you store it in your db as well) as a signature safeguarding the authenticity of the originally uploaded file

    • you don’t actually need a timestamp(+salt) in the dir structure in the context of the present scenario unless you want versioning of the file OR guaranteeing that the same file named differently hasn’t been uploaded(otherwise you’ll end up with different filenames under the same file contents md5 named dir for the given day).

    • not sure why you’d mind about the length of the md5 string. It’s not going to affect performance and md5 is pretty widespread and well supported to use for other purposes as well(e.g. verifying file). But if you really want to cut down on length have a look at http://en.wikipedia.org/wiki/List_of_hash_functions and pick a 16 or 8 or even 4 bit crc to experiment with(again it depends on how you are going to use it, file contents or file names and how large these are).

    • lastly, another alternative would be to do <group>/<user_id>/<filehash>/<timestamp>/<filename> where group will be user ids 1 to <acceptable number of entries in a dir>, say 10000 or less, but that’s something you can find by experimenting on your server for how many entries degrade performance, and when the limit is reached you have a script creating a new group with the same structure. This way you avoid having repetitive/similar info(dates, years, months, timestamps etc), you control the acceptable limits yourself, you got the same file allowed to be uploaded by different users, you got filehash to tell whether a file has been uploaded regardless of the filename, you got versioning by using timestamp, and you got only one file in the end dir with its original(or specified) name. If you are FaceBook and have a billion users, you can have this structure and host clusters of groups of directories across different servers. If you have a small website with say 1000 users you don’t even need the group bit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating an Database for my Application that I am creating however whenever I
I am creating a web application that is accessing a SQLite database in the
In considering languages to use in creating a web-application that interfaces with a database
I am creating a database application using Access 2003 that will be run as
I'm creating a web application that will involve habitual file uploading and retrieval (PDFs,
I am creating a java application that retrieves a userId from a database, transforms
I am creating a window application that need to use sql server database. I
Background: I have created an application that allows users to submit an entry to
I am creating a PyQt application that stores its data in a MySQL database.
I am playing around with Object Oriented Design/Database design by creating an application that

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.