diff options
author | Robin <robin@Amaya.(none)> | 2010-03-26 19:04:35 +0100 |
---|---|---|
committer | Robin <robin@Amaya.(none)> | 2010-03-26 19:04:35 +0100 |
commit | 5cb7524d5c99c1869d0de7e6cf4fb6606d88712f (patch) | |
tree | 68ac2de2e24c4f27566c70a1a760aa7ec5191d4a | |
parent | ba9c95621bccddc8c83689906643a080e1671f22 (diff) | |
download | nextcloud-server-5cb7524d5c99c1869d0de7e6cf4fb6606d88712f.tar.gz nextcloud-server-5cb7524d5c99c1869d0de7e6cf4fb6606d88712f.zip |
added MAX_FILE_SIZE field to upload form
-rw-r--r-- | files/get_files.php | 19 | ||||
-rw-r--r-- | js/lib_files.js | 11 |
2 files changed, 27 insertions, 3 deletions
diff --git a/files/get_files.php b/files/get_files.php index f6db75b3a4b..29f06d289d5 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 8d1039a3b0d..3affcf41a3b 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'); |