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

  • Home
  • SEARCH
  • 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 333309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:56:57+00:00 2026-05-12T09:56:57+00:00

I’m working on a file management system and would like to include an automated

  • 0

I’m working on a file management system and would like to include an automated versioning such as bates numbering if a file with the same name exists. I thought of inserting a “-v0001” between the filename and extension and counting the number of versions as they come in.

$basename = pathinfo($filename, PATHINFO_BASENAME);
$fname = pathinfo($filename, PATHINFO_FILENAME);

 while (filenameExists($basename)) {
     //look for existing -vnnnn (at end of file name)
     if (versioningExists($fname)) {       
         //roll number ahead, set bates number
     } else {
         //start bates numbering at 1    
     }
     //insert bates version number (str_pad)
 }

I’m thinking I would use a regex pattern to check if the versioning exists.

My questions are:

  • What are the potential problems of using a numbering system like this?
  • And what alternatives are there for dealing with filename versioning?

I’m intending this to be a mass import system, so I don’t want to bug the user to give me unique filenames if I don’t have to, and I do have the option of including a selection of other versioning schemes. My system has tags, so filename has a decreased importance, but I would think there is still some importance.

  • 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-05-12T09:56:57+00:00Added an answer on May 12, 2026 at 9:56 am

    In the past I have always just tacked on the results of mktime() before the file extension (when said file name already exists on the system). No need to parse for the current version number and you also get a nice timestamp added to the file name so you can tell which one came first and when it was created. You can check for the file with the timestamp included before saving if you are worried someone else might save the same named file at the same exact second on the server. If that really is a concern, you should probably do the same with your system as well, up the number, then check again to see if a file with that name already exists.

    The timestamp has the added benefit of being far more unlikely someone is uploading a file already named with something similar to your version number, for instance, bob_321235678.jpg compared to bob_1.jpg.

    The one downfall to all this is you can end up with a bunch of files that are more or less the same but with different names, so you may want to parse that data periodically looking for files not in use in the system.

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

Sidebar

Related Questions

No related questions found

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.