效果图
<?php //读取管理项目,并且展示 require_once 'lib/dir.func.php'; require_once 'lib/file.func.php'; date_default_timezone_set("PRC"); error_reporting(E_ALL&~E_NOTICE); define('WEBROOT','webRoot'); $path=$_REQUEST['path']?$_REQUEST['path']:WEBROOT; $act=$_REQUEST['act']?$_REQUEST['act']:''; $dirName=$_REQUEST['dirName']?$_REQUEST['dirName']:''; $fileName=$_REQUEST['fileName']?$_REQUEST['fileName']:''; $info=read_directory($path); // print_r($info);exit; if(!is_array($info)){ exit("<script> alert('读取失败'); location.href='index.php'; </script>"); } //根据不同请求完成不同操作 switch($act){ case 'createDir': // echo $dirName;exit; $res=create_dir($path.DIRECTORY_SEPARATOR.$dirName); if($res===true){ $result['msg']=basename($dirName).'创建成功'; $result['icon']=1; }else{ $result['msg']=$res; $result['icon']=2; } exit(json_encode($result)); break; case 'renameDir': $newName=$path.DIRECTORY_SEPARATOR.$dirName; $res=rename_dir($fileName,$newName); if($res===true){ $result['msg']=$fileName.'重命名成功'; $result['icon']=1; }else{ $result['msg']=$res; $result['icon']=2; } exit(json_encode($result)); break; case 'delDir': $res=del_dir($fileName); if($res===true){ $result['msg']=basename($fileName).'删除成功'; $result['icon']=1; }else{ $result['msg']=$res; $result['icon']=2; } exit(json_encode($result)); break; //文件部分 case 'createFile': $res=create_file($path.DIRECTORY_SEPARATOR.$fileName); if($res===true){ $result['msg']=basename($fileName).'文件新建成功'; $result['icon']=1; }else{ $result['msg']=$res; $result['icon']=2; } exit(json_encode($result)); break; case 'showContents': $res=show_contents($fileName); exit($res); break; } ?> <!DOCTYPE html> <html lang="zh-cn"> head> meta charset="utf-8"http-equiv="X-UA-Compatible" content="IE=edge"name="viewport"="width=device-width,initial-scale=1"title>WEB在线文件管理器</<!-- Bootstrap --> link href="css/bootstrap.min.css" rel="stylesheet"> HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries WARNING: Respond.js doesn't work if you view the page via file:// [if lt IE 9]> <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script> <![endif]--> bodydiv class="container"> ="row clearfix"> ="col-md-12 column"> nav ="navbar navbar-default" role="navigation"> ="navbar-header"> button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> span ="sr-only">切换导航span><="icon-bar"></buttona ="navbar-brand" href="index.php"="glyphicon glyphicon-home">首页adiv> ="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> ul ="nav navbar-nav"> li ="active"> a ="javascript:void(0)"='createDir' data-url="index.php?act=createDir&path=<?php echo $path;?>"="glyphicon glyphicon-folder-open">新建目录li> ="createFile" data-url="index.php?act=createFile&path=<?php echo $path;?>"="glyphicon glyphicon-file">新建文件="#"="glyphicon glyphicon-upload">上传文件="glyphicon glyphicon-info-sign">系统信息ulform ="navbar-form navbar-left"="search"="form-group"input ="text"="form-control" /> ="submit"="btn btn-default">搜索form> nav="jumbotron nofollow"h1> WEB在线文件管理器 p WEB在线文件管理器主要是用于管理项目文件,实现在线编辑、修改、删除等操作。 ="btn btn-primary btn-large">查看更多 »table ="table table-bordered table-hover table-condensed"theadtrth 类型 名称 读/写/执行 访问时间 操作 tbody> 目录部分 --> php if(is_array($info['dir'])){ foreach($info['dir'] as $val){ ?> tr ="success"td="glyphicon glyphicon-folder-close"php echo $val['showName'];?>="glyphicon <?php echo $val['readable']?'glyphicon-ok':'glyphicon-remove';?>"="glyphicon <?php echo $val['writable']?'glyphicon-ok':'glyphicon-remove';?>"="glyphicon <?php echo $val['executable']?'glyphicon-ok':'glyphicon-remove';?>"php echo $val['atime'];="index.php?path=<?php echo $val['fileName'];?>"='btn btn-primary btn-sm'>打开 classbtn-primary btn-sm renameDir' data-url='index.php?act=renameDir&fileName=<?php echo $val['fileName'];?>&path=php echo $path;?>' data-showName='?>'>重命名="#">剪切>复制btn-danger btn-sm delDir' data-url='index.php?act=delDir&fileName=<?php ?>'>删除php } } ?> 文件部分 php if(is_array($info['file'])){ foreach($info['file'] as $val){ ="warning"btn-primary btn-sm showContents' data-url="index.php?act=showContents&fileName=<?php echo $val['fileName'];?>&path=<?php echo $path;?>">查看>编辑>下载>重命名btn-danger btn-sm'>删除?> table> jQuery (necessary for Bootstrap's JavaScript plugins) script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"script Include all compiled plugins (below),or include individual files as needed ="js/bootstrap.min.js"="layer/layer.js"="js/dir.js"="js/file.js"html>
目录函数文件 dir.func.php
<?php /** * 读取目录下的信息返回 * @method read_directory * @param string $path 目标目录 * @return mixed false|array */ function read_directory(string $path){ if(!is_dir()){ return false; } $info=[]; $handle=opendir(); while(($item=@readdir($handle))!==){ if($item!='.'&&$item!='..'){ $filePath=$path.DIRECTORY_SEPARATOR.$item; $info['fileName']=$filePath$info['showName']=$info['readable']=is_readable($filePath)?true:$info['writable']=is_writable($info['executable']=is_executable($info['atime']=date('Y/m/d H:i:s',fileatime()); if(is_file()){ $arr['file'][]=$info; } $arr['dir'][]=; } } } closedir($handlereturn $arr; } * * 创建目录 * @method create_dir * @param string $path 目录名称 * @return mixed true|string function create_dir($path.'当前目录已存在同名文件'; } mkdir($path,755,1)">true$path.'目录创建失败'; } * * 重命名目录 * @method rename_dir * @param string $oldName 原目录 * @param string $newName 新名称 * @return mixed string|true function rename_dir($oldName,1)">$newName$oldNamereturn '原目录不存在'return '当前目录下存在同名文件'rename(return '重命名失败'; } * * 删除目录 * @method del_dir * @param string $path 目录名称 * @return mixed true|string function del_dir(return '目录不存在'$pathName=; $pathName)){ @unlink(); } $func=__FUNCTION__; $func(); } } } rmdir(; }
文件函数 file.func.php
<?* * 创建文件 * @method create_file * @param string $fileName 文件名称 * @param array $allowExt 允许的文件类型 * @return mixed true|string function create_file($fileName,1)">$allowExt=array('txt','html','php')){ $fileName$ext=strtolower(pathinfo(PATHINFO_EXTENSION)); in_array($ext,1)">$allowExtreturn '非法文件类型'touch(return '文件创建失败'* * 查看文件内容 * @method show_contents * @param string $fileName 文件名称 * @param array $allowExt 允许的类型 * @return string 文件内容 function show_contents(array('jpg','jpeg','png','gif','txt',1)">return '文件不存在'//检测是否是真实图片 getimagesize()){ $res="<img src='{$fileName}' class='img-responsive'/>"; }else{ $str=file_get_contents(); strlen($str)>0$res=highlight_string($str,1)">); }{ $res='文件中没有内容'; } } $res; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。