Last active
August 29, 2015 14:25
-
-
Save tuckbloor/2f403e07bf1aecd1d495 to your computer and use it in GitHub Desktop.
while file exists update the file revision number
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
$path = public_path() . '/directory/' . $file_name; | |
$i = 0; | |
while(file_exists($path)) { | |
$i++; | |
if($i == 1) { | |
$file_name = pathinfo($path, PATHINFO_FILENAME); | |
$file_extension = pathinfo($path, PATHINFO_EXTENSION); | |
$file_name = $file_name . '-r' . $i . '.' . $file_extension; | |
$path = public_path() . '/directory'/' . $file_name; | |
} else { | |
$test = $i-1; | |
$file_name =str_replace('-r' . $test . '.pdf', '-r' . $i, $file_name . '.pdf'); | |
$path = public_path() . '/directory/' . $file_name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment