From 8462bf2a8f4ec61b41d175e93dfe0cf31bfe68d1 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Fri, 13 Sep 2013 13:40:26 +0300 Subject: [PATCH] Add (i) if filename already exists. Ref #34 --- ajax/documentController.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ajax/documentController.php b/ajax/documentController.php index 56dd1b68..810cfdb9 100644 --- a/ajax/documentController.php +++ b/ajax/documentController.php @@ -18,8 +18,16 @@ class DocumentController extends Controller{ public static function create($args){ $uid = self::preDispatch(); $view = new \OC\Files\View('/' . $uid . '/files'); + $name = '/New Document.odt'; + $fileNum = 0; + + while ($view->file_exists($name)){ + $fileNum += 1; + $name = preg_replace('/(\.odt|\(\d+\)\.odt)$/', ' (' .$fileNum . ').odt', $name); + }; + $view->file_put_contents( - 'document.odt', + $name, base64_decode(self::ODT_TEMPLATE) ); }