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.