Created
January 24, 2011 02:34
-
-
Save benkulbertis/792728 to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(file_exists($fname)){ | |
if($count == 0) $old_fname = $fname; | |
$count++; | |
$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