diff options
author | Bart Visscher <bartv@thisnet.nl> | 2011-09-23 22:22:59 +0200 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2011-09-25 22:19:28 +0200 |
commit | 17e631bc5e327514596ce8761fe7f93d414a8717 (patch) | |
tree | a2e6bed923a493988028adafaaebcab5b9bfbd39 /files/ajax/upload.php | |
parent | dbddec9160338818009ec7020cec5a2b298aae7e (diff) | |
download | nextcloud-server-17e631bc5e327514596ce8761fe7f93d414a8717.tar.gz nextcloud-server-17e631bc5e327514596ce8761fe7f93d414a8717.zip |
Use OC_JSON for json responses
Create OC_JSON class, for single point of creating json responses.
No real logic change, this just cleans up the code a bit.
Diffstat (limited to 'files/ajax/upload.php')
-rw-r--r-- | files/ajax/upload.php | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/files/ajax/upload.php b/files/ajax/upload.php index f005a8af226..041ec0c92e3 100644 --- a/files/ajax/upload.php +++ b/files/ajax/upload.php @@ -3,19 +3,13 @@ // Init owncloud require_once('../../lib/base.php'); -// We send json data -// header( "Content-Type: application/json" ); // Firefox and Konqueror tries to download application/json for me. --Arthur -header( "Content-Type: text/plain" ); +OC_JSON::setContentTypeHeader('text/plain'); -// Check if we are a user -if( !OC_User::isLoggedIn()){ - echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" ))); - exit(); -} +OC_JSON::checkLoggedIn(); if (!isset($_FILES['files'])) { - echo json_encode( array( "status" => "error", "data" => array( "message" => "No file was uploaded. Unknown error" ))); + OC_JSON::error(array("data" => array( "message" => "No file was uploaded. Unknown error" ))); exit(); } foreach ($_FILES['files']['error'] as $error) { @@ -28,7 +22,7 @@ foreach ($_FILES['files']['error'] as $error) { 4=>$l->t("No file was uploaded"), 6=>$l->t("Missing a temporary folder") ); - echo json_encode( array( "status" => "error", "data" => array( "message" => $errors[$error] ))); + OC_JSON::error(array("data" => array( "message" => $errors[$error] ))); exit(); } } @@ -43,7 +37,7 @@ foreach($files['size'] as $size){ $totalSize+=$size; } if($totalSize>OC_Filesystem::free_space('/')){ - echo json_encode( array( "status" => "error", "data" => array( "message" => "Not enough space available" ))); + OC_JSON::error(array("data" => array( "message" => "Not enough space available" ))); exit(); } @@ -56,12 +50,12 @@ if(strpos($dir,'..') === false){ $result[]=array( "status" => "success", 'mime'=>OC_Filesystem::getMimeType($target),'size'=>OC_Filesystem::filesize($target),'name'=>$files['name'][$i]); } } - echo json_encode($result); + OC_JSON::encodedPrint($result); exit(); }else{ $error='invalid dir'; } -echo json_encode(array( 'status' => 'error', 'data' => array('error' => $error, "file" => $fileName))); +OC_JSON::error(array('data' => array('error' => $error, "file" => $fileName))); ?> |