diff --git a/files/get_files.php b/files/get_files.php index f6db75b3a4bd038a91166bc6d2023cc25432e7d9..29f06d289d56b40bd90783f24fe7b441fa52c210 100644 --- a/files/get_files.php +++ b/files/get_files.php @@ -22,6 +22,22 @@ */ require_once('../inc/lib_base.php'); +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; +} + // header('Content-type: text/plain'); header('Content-type: application/xml'); @@ -29,9 +45,10 @@ $dir=isset($_GET['dir'])?$_GET['dir']:''; $files=OC_FILES::getdirectorycontent($CONFIG_DATADIRECTORY.'/'.$dir); $dirname=$files[0]['directory']; $dirname=substr($dirname,strrpos($dirname,'/')); +$max_upload=min(return_bytes(ini_get('post_max_size')),return_bytes(ini_get('upload_max_filesize'))); ob_clean(); echo "<?xml version='1.0' standalone='yes'?>\n"; -echo "<dir name='$dirname'>\n"; +echo "<dir name='$dirname' max_upload='$max_upload'>\n"; foreach($files as $file){ $attributes=''; foreach($file as $name=>$data){ diff --git a/js/lib_files.js b/js/lib_files.js index 8d1039a3b0dd01d8cbb6a0088e84e092d1155bcb..3affcf41a3b9e9672d1beb14dbb237533c4fd93e 100644 --- a/js/lib_files.js +++ b/js/lib_files.js @@ -26,6 +26,8 @@ OC_FILES.getdirectorycontent_parse=function(req){ var files=new Array(); var response=req.responseXML; if(response){ + var dir=response.getElementsByTagName('dir').item(0); + files['max_upload']=dir.getAttribute('max_upload'); var fileElements=response.getElementsByTagName('file'); if(fileElements.length>0){ for(index in fileElements){ @@ -205,11 +207,11 @@ OC_FILES.showbrowser_callback=function(content){ tr.appendChild(td); td.className='upload'; td.setAttribute('colspan','5'); - this.showuploader(dir,td); + this.showuploader(dir,td,content['max_upload']); contentNode.appendChild(files); } -OC_FILES.showuploader=function(dir,parent){ +OC_FILES.showuploader=function(dir,parent,max_upload){ this.uploadForm=document.createElement('form'); this.uploadForm.setAttribute('target','uploadIFrame'); this.uploadForm.setAttribute('action','files/upload.php?dir='+dir); @@ -219,6 +221,11 @@ OC_FILES.showuploader=function(dir,parent){ this.uploadIFrame.className='hidden'; this.uploadIFrame.name='uploadIFrame'; parent.appendChild(this.uploadIFrame); + var input=document.createElement('input'); + input.setAttribute('type','hidden'); + input.setAttribute('name','MAX_FILE_SIZE'); + input.setAttribute('value',max_upload); + this.uploadForm.appendChild(input); var file=document.createElement('input'); file.name='file'; file.setAttribute('type','file');