Skip to content

Instantly share code, notes, and snippets.

@putzflorian
Created May 21, 2013 08:03
Show Gist options
  • Select an option

  • Save putzflorian/5618226 to your computer and use it in GitHub Desktop.

Select an option

Save putzflorian/5618226 to your computer and use it in GitHub Desktop.
getSafeFilename for assets or objects
<?php
protected function getSafeFilename($targetPath, $filename) {
$originalFilename = $filename;
$count = 1;
if ($targetPath == "/") {
$targetPath = "";
}
while (true) {
if (Asset_Service::pathExists($targetPath . "/" . $filename)) {
$filename = str_replace("." . Pimcore_File::getFileExtension($originalFilename), "_" . $count . "." . Pimcore_File::getFileExtension($originalFilename), $originalFilename);
$count++;
}
else {
return $filename;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment