From 5da12fcfa13f2c3497470edc97315363aa89e47c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 6 Sep 2010 23:09:14 +0200 Subject: [PATCH] use json to encode the file list, should work better with filenames containing non-ascii characters --- files/api.php | 22 ++++++++++++++++++++-- js/lib_files.js | 21 ++++++++++----------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/files/api.php b/files/api.php index d6e04d4550..3cb796d432 100644 --- a/files/api.php +++ b/files/api.php @@ -53,7 +53,10 @@ if($arguments['action']){ OC_FILES::get($arguments['dir'],$arguments['file']); break; case 'getfiles': - echo json_encode(OC_FILES::getdirectorycontent($arguments['dir'])); + $max_upload=min(return_bytes(ini_get('post_max_size')),return_bytes(ini_get('upload_max_filesize'))); + $files=OC_FILES::getdirectorycontent($arguments['dir']); + $files['__max_upload']=$max_upload; + echo json_encode($files); break; case 'gettree': echo json_encode(OC_FILES::getTree($arguments['dir'])); @@ -80,4 +83,19 @@ if($arguments['action']){ } } -?> \ No newline at end of file +function return_bytes($val) { + $val = trim($val); + $last = strtolower($val[strlen($val)-1]); + switch($last) { + // The 'G' modifier is available since PHP 5.1.0 + case 'g': + $val *= 1024; + case 'm': + $val *= 1024; + case 'k': + $val *= 1024; + } + + return $val; +} +?> diff --git a/js/lib_files.js b/js/lib_files.js index 94af0b896a..f28a46d3a0 100644 --- a/js/lib_files.js +++ b/js/lib_files.js @@ -41,18 +41,16 @@ OC_FILES.xmlloader=new OCXMLLoader(); OC_FILES.getdirectorycontent_parse=function(req){ var files=new Array(); - var response=req.responseXML; + var json=eval('('+req.responseText+')'); OC_FILES.cache.files=Array(); - if(response){ - var dir=response.getElementsByTagName('dir').item(0); - var fileElements=response.getElementsByTagName('file'); - if(fileElements.length>0){ - for(index=0;index