Skip to content

Instantly share code, notes, and snippets.

@tuckbloor
Last active August 29, 2015 14:25
Show Gist options
  • Save tuckbloor/2f403e07bf1aecd1d495 to your computer and use it in GitHub Desktop.
Save tuckbloor/2f403e07bf1aecd1d495 to your computer and use it in GitHub Desktop.
while file exists update the file revision number
$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