Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Checks if the file name exists, if it does uses recursion to append the file name with a number that has not yet been used.
function duplicate_fixer($fname, $count = 0, $old_fname = null){
if($count != 0){
$boom = explode(".", $old_fname);
$boom[count($boom)-2] = $boom[count($boom)-2].$count.".";
$fname = implode($boom);
if($count == 0) $old_fname = $fname;
$fname = duplicate_fixer($fname, $count, $old_fname);
return $fname;
} else {
return $fname;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment