为方便团队交流共享文件,借鉴慕课网上教学视频制作的一个在线文件管理器,采用现下流行的angularjs框架,实现文件的在线浏览,修改,删除,上传和下载等基本功能。未来还将添加用户权限管理,以及并发事件处理的模块。 ?php/** * @author: qjw * @date: 201
为方便团队交流共享文件,借鉴慕课网上教学视频制作的一个在线文件管理器,采用现下流行的angularjs框架,实现文件的在线浏览,修改,删除,上传和下载等基本功能。未来还将添加用户权限管理,以及并发事件处理的模块。
online file manager
在线文件管理器 {{item}}
请选择需要上传的文件
上传文件 取消
{{filename}} 文件内容 提交修改 返回
{{filecontent}}
编号 名称 类型 大小 创建时间 修改时间 访问时间 操作
{{item.num}} {{item.name}} {{item.size}} {{item.createtime}} {{item.modifytime}} {{item.visittime}}
/* * @author: qjw* @date: 2015-09-02 16:15:30*/angular.module('filemanager',[]).service('data',function(){ return null;}).controller('filemanagercontroller',function($scope,$http,data){ function showdetail(t,filename){ $(#showimg).attr(src,filename); $(#showdetail).dialog({ height:auto, width: auto, position: {my: top, at: center, collision:fit}, modal:false,//是否模式对话框 draggable:true,//是否允许拖拽 resizable:true,//是否允许拖动 title:t,//对话框标题 show:slide, hide:explode }); } function getrequest(){ var url = location.search; //获取url中?符后的字串 url=decodeuri(url); var therequest = new object(); if (url.indexof(?) != -1) { var str = url.substr(1); strs = str.split(&); for(var i = 0; i < strs.length; i ++) { therequest[strs[i].split(=)[0]]=unescape(strs[i].split(=)[1]); } } return therequest; } var request= new object(); $scope.path='../xmues'; request=getrequest(); if(request['location']){ $scope.path=request['location']; } $scope.serviceurl=_service_filemanager.php; $scope.pathway=$scope.path.split('/'); console.log($scope.path); console.log($scope.pathway); $scope.content_show=false; $scope.newpath=false; $scope.upload_show=false; $scope.param={action:opendir,path:$scope.path}; getdata($http, $scope.serviceurl, $scope.param, function (data) { $scope.fileinfo=data; console.log(data); }); $scope.turnback=function(){ $scope.content_show=false; $scope.upload_show=false; } $scope.showcontent=function(location,name,type){ var typeflag=new array(); typeflag=type.split('_'); if(typeflag[0]=='file'){ var ext,flag; var res=new array(); var imageext=new array(gif,jpg,jpeg,png,psd); res=name.split('.') ext=res[1].tolowercase() flag=imageext.indexof(ext); if(flag==-1){ $scope.content_show=true; $scope.location=location; $scope.filename=name; $scope.param={action:showcontent,location:$scope.location}; getdata($http, $scope.serviceurl, $scope.param, function (data) { $scope.filecontent=data; }); } else{ showdetail(name,location); } } else{ window.location.href=filemanager.php?location=+location; } } $scope.deletefile=function(location,type){ if(window.confirm(您确定要删除嘛?删除之后无法恢复哟!!!)){ var typeflag=new array(); typeflag=type.split('_'); if(typeflag[0]=='file'){ window.location.href=_service_filemanager.php?action=deletefile&location=+location; } else{ window.location.href=_service_filemanager.php?action=deletefolder&location=+location; } } } $scope.downloadfile=function(location,type){ window.location.href=_service_filemanager.php?action=downloadfile&location=+location; } $scope.upload=function(){ $scope.upload_show=true; } $scope.turnto=function(p){ if(p=='xmues'){ window.location.href=filemanager.php?location=../xmues; } if(p=='..'){ window.location.href=filemanager.php?location=../xmues; } else{ var pos,turn; pos=$scope.path.indexof(p)+p.length; turn=$scope.path.slice(0, pos); window.location.href=filemanager.php?location=+turn; } }})
= 1024 ) { $size /= 1024; $i ++; } return round ( $size, 2 ) . $arr [$i];}function delfile($filename){ if(unlink($filename)){ $mes=文件删除成功; }else{ $mes=文件删除失败; } return $mes;}function downfile($filename){ header(content-disposition:attachment;filename=.basename($filename)); header(content-length:.filesize($filename)); readfile($filename);}function dirsize($path){ $sum=0; global $sum; $handle=opendir($path); while(($item=readdir($handle))!==false){ if($item!=.&&$item!=..){ if(is_file($path./.$item)){ $sum+=filesize($path./.$item); } if(is_dir($path./.$item)){ $func=__function__; $func($path./.$item); } } } closedir($handle); return $sum;}function delfolder($path){ $handle=opendir($path); while(($item=readdir($handle))!==false){ if($item!=.&&$item!=..){ if(is_file($path./.$item)){ unlink($path./.$item); } if(is_dir($path./.$item)){ $func=__function__; $func($path./.$item); } } } closedir($handle); rmdir($path); return 文件夹删除成功;}function getext($filename){ return strtolower(pathinfo($filename,pathinfo_extension));}function uploadfile($fileinfo,$path,$allowext=array(gif,jpeg,jpg,png,txt),$maxsize=10485760){ print_r($fileinfo); if($fileinfo['error']==upload_err_ok){ if(is_uploaded_file($fileinfo['tmp_name'])){ $ext=getext($fileinfo['name']); $destination=$path./.pathinfo($fileinfo['name'],pathinfo_filename)...$ext; if(in_array($ext,$allowext)){ if($fileinfo['size']