From 0718c92dc805f7379b1dbffcd35155dc7e828b9f Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 8 Aug 2013 22:13:53 +0200 Subject: [PATCH 1/4] Do not repeat definition of $target. --- apps/files/ajax/newfile.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php index 8548fc95ddf..8ee4888b34d 100644 --- a/apps/files/ajax/newfile.php +++ b/apps/files/ajax/newfile.php @@ -54,6 +54,8 @@ function progress($notification_code, $severity, $message, $message_code, $bytes } } +$target = $dir.'/'.$filename; + if($source) { if(substr($source, 0, 8)!='https://' and substr($source, 0, 7)!='http://') { OCP\JSON::error(array("data" => array( "message" => "Not a valid source" ))); @@ -62,7 +64,6 @@ if($source) { $ctx = stream_context_create(null, array('notification' =>'progress')); $sourceStream=fopen($source, 'rb', false, $ctx); - $target=$dir.'/'.$filename; $result=\OC\Files\Filesystem::file_put_contents($target, $sourceStream); if($result) { $meta = \OC\Files\Filesystem::getFileInfo($target); @@ -76,14 +77,14 @@ if($source) { exit(); } else { if($content) { - if(\OC\Files\Filesystem::file_put_contents($dir.'/'.$filename, $content)) { - $meta = \OC\Files\Filesystem::getFileInfo($dir.'/'.$filename); + if(\OC\Files\Filesystem::file_put_contents($target, $content)) { + $meta = \OC\Files\Filesystem::getFileInfo($target); $id = $meta['fileid']; OCP\JSON::success(array("data" => array('content'=>$content, 'id' => $id))); exit(); } - }elseif(\OC\Files\Filesystem::touch($dir . '/' . $filename)) { - $meta = \OC\Files\Filesystem::getFileInfo($dir.'/'.$filename); + }elseif(\OC\Files\Filesystem::touch($target)) { + $meta = \OC\Files\Filesystem::getFileInfo($target); $id = $meta['fileid']; OCP\JSON::success(array("data" => array('content'=>$content, 'id' => $id, 'mime' => $meta['mimetype']))); exit(); From 1ed049a6828149e00d424a3dac87b3d1b1777d6a Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 8 Aug 2013 21:27:59 +0200 Subject: [PATCH 2/4] Do not repeat JSON success code. --- apps/files/ajax/newfile.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php index 8ee4888b34d..22598ee78e1 100644 --- a/apps/files/ajax/newfile.php +++ b/apps/files/ajax/newfile.php @@ -76,14 +76,14 @@ if($source) { $eventSource->close(); exit(); } else { + $success = false; if($content) { - if(\OC\Files\Filesystem::file_put_contents($target, $content)) { - $meta = \OC\Files\Filesystem::getFileInfo($target); - $id = $meta['fileid']; - OCP\JSON::success(array("data" => array('content'=>$content, 'id' => $id))); - exit(); - } - }elseif(\OC\Files\Filesystem::touch($target)) { + $success = \OC\Files\Filesystem::file_put_contents($target, $content); + } else { + $success = \OC\Files\Filesystem::touch($target); + } + + if($success) { $meta = \OC\Files\Filesystem::getFileInfo($target); $id = $meta['fileid']; OCP\JSON::success(array("data" => array('content'=>$content, 'id' => $id, 'mime' => $meta['mimetype']))); @@ -91,5 +91,4 @@ if($source) { } } - OCP\JSON::error(array("data" => array( "message" => "Error when creating the file" ))); From 0ab885047867ba9b28514e5e4f93136e74837fe5 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 8 Aug 2013 21:35:18 +0200 Subject: [PATCH 3/4] Adjust JSON code to stable5. --- apps/files/ajax/newfile.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php index 22598ee78e1..46149c3e8bd 100644 --- a/apps/files/ajax/newfile.php +++ b/apps/files/ajax/newfile.php @@ -86,7 +86,8 @@ if($source) { if($success) { $meta = \OC\Files\Filesystem::getFileInfo($target); $id = $meta['fileid']; - OCP\JSON::success(array("data" => array('content'=>$content, 'id' => $id, 'mime' => $meta['mimetype']))); + $mime = $meta['mimetype']; + OCP\JSON::success(array("data" => array('mime'=>$mime, 'content'=>$content, 'id' => $id))); exit(); } } From beb27168de3e81f71c894ee64561d029b3b2b02c Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 8 Aug 2013 21:36:10 +0200 Subject: [PATCH 4/4] Use multiple lines for the JSON data array. --- apps/files/ajax/newfile.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php index 46149c3e8bd..8c1aad8668c 100644 --- a/apps/files/ajax/newfile.php +++ b/apps/files/ajax/newfile.php @@ -87,7 +87,11 @@ if($source) { $meta = \OC\Files\Filesystem::getFileInfo($target); $id = $meta['fileid']; $mime = $meta['mimetype']; - OCP\JSON::success(array("data" => array('mime'=>$mime, 'content'=>$content, 'id' => $id))); + OCP\JSON::success(array('data' => array( + 'id' => $id, + 'mime' => $mime, + 'content' => $content, + ))); exit(); } }