added MAX_FILE_SIZE field to upload form

This commit is contained in:
Robin 2010-03-26 19:04:35 +01:00
parent ba9c95621b
commit 5cb7524d5c
2 changed files with 27 additions and 3 deletions

View File

@ -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){

View File

@ -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');