Created
May 21, 2013 08:03
-
-
Save putzflorian/5618226 to your computer and use it in GitHub Desktop.
getSafeFilename for assets or objects
This file contains hidden or 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
| <?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