diff options
author | Robin <robin@Amaya.(none)> | 2010-04-25 15:04:13 +0200 |
---|---|---|
committer | Robin <robin@Amaya.(none)> | 2010-04-25 15:04:13 +0200 |
commit | afc0ef420b58b92e38ea600c2eac972ed132fbac (patch) | |
tree | 3ced70c323eb110da0738b75556783953cf85322 | |
parent | c2bdd6134be53dcf822632192af10cf3cf80be1e (diff) | |
download | nextcloud-server-afc0ef420b58b92e38ea600c2eac972ed132fbac.tar.gz nextcloud-server-afc0ef420b58b92e38ea600c2eac972ed132fbac.zip |
bug fix when starting multiply uploads while the old ones arent finsihed, detect file actions on mimetype not on extention
-rw-r--r-- | files/upload.php | 2 | ||||
-rwxr-xr-x | inc/lib_files.php | 66 | ||||
-rw-r--r-- | js/filebrowser.js | 6 | ||||
-rw-r--r-- | js/lib_files.js | 48 |
4 files changed, 102 insertions, 20 deletions
diff --git a/files/upload.php b/files/upload.php index b5fed2ed5b1..0aa435cad6f 100644 --- a/files/upload.php +++ b/files/upload.php @@ -22,6 +22,8 @@ */ require_once('../inc/lib_base.php'); +// sleep(5); //immitate slow internet. + $fileName=$_FILES['file']['name']; $source=$_FILES['file']['tmp_name']; $target=$CONFIG_DATADIRECTORY.'/'.$_GET['dir'].'/'.$fileName; diff --git a/inc/lib_files.php b/inc/lib_files.php index a4e1c6a5a4f..6188723c028 100755 --- a/inc/lib_files.php +++ b/inc/lib_files.php @@ -59,6 +59,7 @@ class OC_FILES { $file['directory']=$directory; $stat=stat($directory.'/'.$filename); $file=array_merge($file,$stat); + $file['mime']=OC_FILES::getMimeType($directory .'/'. $filename); $file['type']=filetype($directory .'/'. $filename); if($file['type']=='dir'){ $dirs[$file['name']]=$file; @@ -190,6 +191,71 @@ class OC_FILES { } } } + + /** + * try to detect the mime type of a file + * + * @param string file path + * @return string guessed mime type + */ + function getMimeType($fspath){ + if (@is_dir($fspath)) { + // directories are easy + return "httpd/unix-directory"; + } else if (function_exists("mime_content_type")) { + // use mime magic extension if available + $mime_type = mime_content_type($fspath); + } else if ($this->_can_execute("file")) { + // it looks like we have a 'file' command, + // lets see it it does have mime support + $fp = popen("file -i '$fspath' 2>/dev/null", "r"); + $reply = fgets($fp); + pclose($fp); + + // popen will not return an error if the binary was not found + // and find may not have mime support using "-i" + // so we test the format of the returned string + + // the reply begins with the requested filename + if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) { + $reply = substr($reply, strlen($fspath)+2); + // followed by the mime type (maybe including options) + if (preg_match('/^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*/', $reply, $matches)) { + $mime_type = $matches[0]; + } + } + } + if (empty($mime_type)) { + // Fallback solution: try to guess the type by the file extension + // TODO: add more ... + switch (strtolower(strrchr(basename($fspath), "."))) { + case ".html": + $mime_type = "text/html"; + break; + case ".txt": + $mime_type = "text/plain"; + break; + case ".css": + $mime_type = "text/css"; + break; + case ".gif": + $mime_type = "image/gif"; + break; + case ".jpg": + $mime_type = "image/jpeg"; + break; + case ".jpg": + $mime_type = "png/jpeg"; + break; + default: + $mime_type = "application/octet-stream"; + break; + } + } + + return $mime_type; + } + } function zipAddDir($dir,$zip,$internalDir=''){ diff --git a/js/filebrowser.js b/js/filebrowser.js index f12cec44143..cc03fe33156 100644 --- a/js/filebrowser.js +++ b/js/filebrowser.js @@ -129,16 +129,16 @@ OC_FILES.browser.files.show=function(parent,fileList){ for(name in fileList){ file=fileList[name]; if(!OC_FILES.browser.files.fileNodes[file.name]){ - OC_FILES.browser.files.add(file.name,file.type,file.size,file.date); + OC_FILES.browser.files.add(file.name,file.type,file.size,file.date,file.mime); } } } } -OC_FILES.browser.files.add=function(name,type,size,date){ +OC_FILES.browser.files.add=function(name,type,size,date,mime){ if(name){ if(!size) size=0; if(!date) date=getTimeString(); - OC_FILES.files[name]=new OC_FILES.file(OC_FILES.dir,name,type); + OC_FILES.files[name]=new OC_FILES.file(OC_FILES.dir,name,type,mime); tr=document.createElement('tr'); OC_FILES.browser.files.fileNodes[name]=tr; OC_FILES.browser.files.tbody.appendChild(tr); diff --git a/js/lib_files.js b/js/lib_files.js index 7c23ee16a9d..f60b399746d 100644 --- a/js/lib_files.js +++ b/js/lib_files.js @@ -49,7 +49,7 @@ OC_FILES.getdirectorycontent_parse=function(req){ if(fileElements.length>0){ for(index=0;index<fileElements.length;index++){ var file=new Array(); - var attributes=Array('size','name','type','directory','date'); + var attributes=Array('size','name','type','directory','date','mime'); for(i in attributes){ var name=attributes[i]; file[name]=fileElements.item(index).getAttribute(name); @@ -106,6 +106,11 @@ OC_FILES.upload=function(dir,iframeId){ return false; } } + var mime=''; + if(fileSelector.files && fileSelector.files[0].type){ + var mime=fileSelector.files[0].type; + } + file.dir=dir; file.dir=dir; file.name=name; file.type='file'; @@ -118,9 +123,10 @@ OC_FILES.upload=function(dir,iframeId){ OC_FILES.cache.incomplete[dir][name]['name']=name; OC_FILES.cache.incomplete[dir][name]['type']='incomplete'; OC_FILES.cache.incomplete[dir][name]['size']=size; + OC_FILES.cache.incomplete[dir][name]['mime']=mime; OC_FILES.uploadIFrames[iframeId].file=file; OC_FILES.uploadIFrames[iframeId].addEvent('onload',new callBack(OC_FILES.upload_callback,OC_FILES.uploadIFrames[iframeId])); - OC_FILES.browser.files.add(name,'incomplete',size); + OC_FILES.browser.files.add(name,'incomplete',size,null,mime); OC_FILES.uploadForm.submit(); if(OC_FILES.uploadForm.parentElement){ OC_FILES.uploadForm.className='hidden'; @@ -137,11 +143,11 @@ OC_FILES.upload_callback=function(iframeId){ if(OC_FILES.cache.incomplete[file.dir][file.name]){ OC_FILES.browser.files.remove(file.name); OC_FILES.cache.files[file.name]=OC_FILES.cache.incomplete[file.dir][file.name] - OC_FILES.cache.incomplete[file.dir][file.name]=null; + delete OC_FILES.cache.incomplete[file.dir][file.name]; OC_FILES.cache.files[file.name]['type']=file.type; this.uploadForm.parentNode.removeChild(this.uploadForm); this.parentNode.removeChild(this); - delete OC_FILES.uploadIFrames[file.iframeId]; + OC_FILES.uploadIFrames[file.iframeId]=null; OC_FILES.browser.show(file.dir); } } @@ -305,11 +311,17 @@ OC_FILES.actions_selected['delete']=function(){ OC_FILES.files=Array(); -OC_FILES.file=function(dir,file,type){ +OC_FILES.file=function(dir,file,type,mime){ if(file){ this.type=type; this.file=file; this.dir=dir; + this.mime=mime; + if(mime){ + var mimeParts=mime.split('/'); + this.mime1=mimeParts[0]; + this.mime2=mimeParts[1]; + } this.actions=new Object(); if(file.lastIndexOf('.')){ this.extention=file.substr(file.lastIndexOf('.')+1); @@ -328,10 +340,17 @@ OC_FILES.file=function(dir,file,type){ } } } - if(OC_FILES.fileActions[this.extention]){ - for(index in OC_FILES.fileActions[this.extention]){ - if(OC_FILES.fileActions[this.extention][index].call){ - this.actions[index]=OC_FILES.fileActions[this.extention][index]; + if(OC_FILES.fileActions[this.mime1]){ + for(index in OC_FILES.fileActions[this.mime1]){ + if(OC_FILES.fileActions[this.mime1][index].call){ + this.actions[index]=OC_FILES.fileActions[this.mime1][index]; + } + } + } + if(OC_FILES.fileActions[this.mime]){ + for(index in OC_FILES.fileActions[this.mime]){ + if(OC_FILES.fileActions[this.mime][index].call){ + this.actions[index]=OC_FILES.fileActions[this.mime][index]; } } } @@ -372,15 +391,10 @@ OC_FILES.fileActions.dir.dropOn=function(file){ OC_FILES.move(file.file,file.file,file.dir,this.dir+'/'+this.file); } -OC_FILES.fileActions.jpg=new Object() +OC_FILES.fileActions.image=new Object() -OC_FILES.fileActions.jpg.show=function(){ +OC_FILES.fileActions.image.show=function(){ OC_FILES.browser.showImage(this.dir,this.file); } -OC_FILES.fileActions.jpg['default']=OC_FILES.fileActions.jpg.show; - -OC_FILES.fileActions.jpeg=OC_FILES.fileActions.jpg -OC_FILES.fileActions.png=OC_FILES.fileActions.jpg -OC_FILES.fileActions.gif=OC_FILES.fileActions.jpg -OC_FILES.fileActions.bmp=OC_FILES.fileActions.jpg
\ No newline at end of file +OC_FILES.fileActions.image['default']=OC_FILES.fileActions.image.show;
\ No newline at end of file |