diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2012-04-15 16:59:39 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2012-04-15 17:00:49 +0200 |
commit | a0d917fe98efbb11905f7ddd12169e3675690555 (patch) | |
tree | ee8780be20f979c848e155412ed64c81367e826e /lib | |
parent | 0b426b5e64eec4b255c1e767edb07e01160eb074 (diff) | |
download | nextcloud-server-a0d917fe98efbb11905f7ddd12169e3675690555.tar.gz nextcloud-server-a0d917fe98efbb11905f7ddd12169e3675690555.zip |
fixing oc-375 - a number is appended tp the filename
Diffstat (limited to 'lib')
-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; + } } |