diff options
author | Tom Needham <needham.thomas@gmail.com> | 2012-04-15 15:09:54 +0000 |
---|---|---|
committer | Tom Needham <needham.thomas@gmail.com> | 2012-04-15 15:09:54 +0000 |
commit | b0e68d039c17c26013460f890c148595652b5376 (patch) | |
tree | ef3c4149316a9edbb8f1651315116e39878cba5a /lib/helper.php | |
parent | 712e25bb02518f353edddc5e9acbb56b80e2affb (diff) | |
parent | a0d917fe98efbb11905f7ddd12169e3675690555 (diff) | |
download | nextcloud-server-b0e68d039c17c26013460f890c148595652b5376.tar.gz nextcloud-server-b0e68d039c17c26013460f890c148595652b5376.zip |
Merge branch 'master' of gitorious.org:owncloud/owncloud
Diffstat (limited to 'lib/helper.php')
-rwxr-xr-x | lib/helper.php | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/helper.php b/lib/helper.php index c33db5f10fe..412f0e6b764 100755 --- a/lib/helper.php +++ b/lib/helper.php @@ -492,4 +492,32 @@ class OC_Helper { } } } + + /** + * Adds a suffix to the name in case the file exists + * + * @param $path + * @param $filename + * @return string + */ + public static function buildNotExistingFileName($path, $filename) + { + if ($pos = strrpos($filename, '.')) { + $name = substr($filename, 0, $pos); + $ext = substr($filename, $pos); + } else { + $name = $filename; + } + + $newpath = $path . '/' . $filename; + $newname = $filename; + $counter = 2; + while (OC_Filesystem::file_exists($newpath)) { + $newname = $name . ' (' . $counter . ')' . $ext; + $newpath = $path . '/' . $newname; + $counter++; + } + + return $newname; + } } |