效果图
<?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"> <Meta http-equiv="X-UA-Compatible" content="IE=edge"> <Meta name="vIEwport" content="wIDth=device-wIDth, initial-scale=1"> <Title>WEB在线文件管理器</Title> <!-- bootstrap --> <@R_404_6862@ 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]--> </head> <body> <p class="container"> <p class="row clearfix"> <p class="col-md-12 column"> <nav class="navbar navbar-default" role="navigation"> <p class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">切换导航</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button> <a class="navbar-brand" href="index.PHP"><span class="glyphicon glyphicon-home"></span>首页</a> </p> <p class="collapse navbar-collapse" ID="bs-example-navbar-collapse-1"> <ul class="nav navbar-nav"> <li class="active"> <a href="JavaScript:voID(0)" class='createDir' data-url="index.PHP?act=createDir&path=<?PHP echo $path;?>"><span class="glyphicon glyphicon-folder-open"></span>新建目录</a> </li> <li> <a href="JavaScript:voID(0)" class="createfile" data-url="index.PHP?act=createfile&path=<?PHP echo $path;?>"><span class="glyphicon glyphicon-file"></span>新建文件</a> </li> <li> <a href="#"><span class="glyphicon glyphicon-upload"></span>上传文件</a> </li> <li> <a href="#"><span class="glyphicon glyphicon-info-sign"></span>系统信息</a> </li> </ul> </li> </ul> <form class="navbar-form navbar-left" role="search"> <p class="form-group"> <input type="text" class="form-control" /> </p> <button type="submit" class="btn btn-default">搜索</button> </form> </p> </nav> <p class="jumbotron nofollow"> <h1> WEB在线文件管理器 </h1> <p> WEB在线文件管理器主要是用于管理项目文件,实现在线编辑、修改、删除等 *** 作。 </p> <p> <a class="btn btn-primary btn-large" href="#">查看更多 »</a> </p> </p> <table class="table table-bordered table-hover table-condensed"> <thead> <tr> <th> 类型 </th> <th> 名称 </th> <th> 读/写/执行 </th> <th> 访问时间 </th> <th> *** 作 </th> </tr> </thead> <tbody> <!-- 目录部分 --> <?PHP if(is_array($info['dir'])){ foreach($info['dir'] as $val){ ?> <tr class="success"> <td><span class="glyphicon glyphicon-folder-close"></span></td> <td><?PHP echo $val['showname'];?></td> <td> <span class="glyphicon <?PHP echo $val['readable']?'glyphicon-ok':'glyphicon-remove';?>"></span> <span class="glyphicon <?PHP echo $val['writable']?'glyphicon-ok':'glyphicon-remove';?>"></span> <span class="glyphicon <?PHP echo $val['executable']?'glyphicon-ok':'glyphicon-remove';?>"></span> </td> <td><?PHP echo $val['atime'];?></td> <td> <a href="index.PHP?path=<?PHP echo $val['filename'];?>" class='btn btn-primary btn-sm'>打开</a> <a href="JavaScript:voID(0)" class='btn btn-primary btn-sm renameDir' data-url='index.PHP?act=renameDir&filename=<?PHP echo $val['filename'];?>&path=<?PHP echo $path;?>' data-showname='<?PHP echo $val['showname'];?>'>重命名</a> <a href="#" class='btn btn-primary btn-sm'>剪切</a> <a href="#" class='btn btn-primary btn-sm'>复制</a> <a href="JavaScript:voID(0)" class='btn btn-danger btn-sm delDir' data-url='index.PHP?act=delDir&filename=<?PHP echo $val['filename'];?>&path=<?PHP echo $path;?>' data-showname='<?PHP echo $val['showname'];?>'>删除</a> </td> </tr> <?PHP } } ?> <!-- 文件部分 --> <?PHP if(is_array($info['file'])){ foreach($info['file'] as $val){ ?> <tr class="warning"> <td><span class="glyphicon glyphicon-file"></span></td> <td><?PHP echo $val['showname'];?></td> <td> <span class="glyphicon <?PHP echo $val['readable']?'glyphicon-ok':'glyphicon-remove';?>"></span> <span class="glyphicon <?PHP echo $val['writable']?'glyphicon-ok':'glyphicon-remove';?>"></span> <span class="glyphicon <?PHP echo $val['executable']?'glyphicon-ok':'glyphicon-remove';?>"></span> </td> <td><?PHP echo $val['atime'];?></td> <td> <a href="#" class='btn btn-primary btn-sm showContents' data-url="index.PHP?act=showContents&filename=<?PHP echo $val['filename'];?>&path=<?PHP echo $path;?>">查看</a> <a href="#" class='btn btn-primary btn-sm'>编辑</a> <a href="#" class='btn btn-primary btn-sm'>下载</a> <a href="#" class='btn btn-primary btn-sm'>重命名</a> <a href="#" class='btn btn-primary btn-sm'>剪切</a> <a href="#" class='btn btn-primary btn-sm'>复制</a> <a href="#" class='btn btn-danger btn-sm'>删除</a> </td> </tr> <?PHP } } ?> </tbody> </table> </p> </p> </p> <!-- 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 inpIDual files as needed --> <script src="Js/bootstrap.min.Js"></script> <script src="layer/layer.Js"></script> <script src="Js/dir.Js"></script> <script src="Js/file.Js"></script> </body></HTML>
目录函数文件 dir.func.PHP
<?PHP/** * 读取目录下的信息返回 * @method read_directory * @param string $path 目标目录 * @return mixed false|array */function read_directory(string $path){ if(!is_dir($path)){ return false; } $info=[]; $handle=opendir($path); while(($item=@readdir($handle))!==false){ if($item!='.'&&$item!='..'){ $filePath=$path.DIRECTORY_SEParaTOR.$item; $info['filename']=$filePath; $info['showname']=$item; $info['readable']=is_readable($filePath)?true:false; $info['writable']=is_writable($filePath)?true:false; $info['executable']=is_executable($filePath)?true:false; $info['atime']=date('Y/m/d H:i:s',fileatime($filePath)); if(is_file($filePath)){ $arr['file'][]=$info; } if(is_dir($filePath)){ $arr['dir'][]=$info; } } } closedir($handle); return $arr;}/** * 创建目录 * @method create_dir * @param string $path 目录名称 * @return mixed true|string */function create_dir(string $path){ if(is_dir($path)){ return $path.'当前目录已存在同名文件'; } if(!mkdir($path,755,true)){ return $path.'目录创建失败'; } return true;}/** * 重命名目录 * @method rename_dir * @param string $oldname 原目录 * @param string $newname 新名称 * @return mixed string|true */function rename_dir(string $oldname,string $newname){ if(!is_dir($oldname)){ return '原目录不存在'; } if(is_dir($newname)){ return '当前目录下存在同名文件'; } if(!rename($oldname,$newname)){ return '重命名失败'; } return true;}/** * 删除目录 * @method del_dir * @param string $path 目录名称 * @return mixed true|string */function del_dir(string $path){ if(!is_dir($path)){ return '目录不存在'; } $handle=opendir($path); while(($item=@readdir($handle))!==false){ if($item!='.'&&$item!='..'){ $pathname=$path.DIRECTORY_SEParaTOR.$item; if(is_file($pathname)){ @un@R_404_6862@($pathname); } if(is_dir($pathname)){ $func=__FUNCTION__; $func($pathname); } } } closedir($handle); rmdir($path); return true;}
文件函数 file.func.PHP
<?PHP/** * 创建文件 * @method create_file * @param string $filename 文件名称 * @param array $allowExt 允许的文件类型 * @return mixed true|string */function create_file(string $filename,$allowExt=array('txt','HTML','PHP')){ if(is_file($filename)){ return '当前目录下存在同名文件'; } $ext=strtolower(pathinfo($filename,PATHINFO_EXTENSION)); if(!in_array($ext,$allowExt)){ return '非法文件类型'; } if(!touch($filename)){ return '文件创建失败'; } return true;}/** * 查看文件内容 * @method show_contents * @param string $filename 文件名称 * @param array $allowExt 允许的类型 * @return string 文件内容 */function show_contents(string $filename,$allowExt=array('jpg','jpeg','png','gif','txt','HTML','PHP')){ if(!is_file($filename)){ return '文件不存在'; } $ext=strtolower(pathinfo($filename,PATHINFO_EXTENSION)); if(!in_array($ext,$allowExt)){ return '非法文件类型'; } //检测是否是真实图片 if(getimagesize($filename)){ $res="<img src='{$filename}' class='img-responsive'/>"; }else{ $str=file_get_contents($filename); if(strlen($str)>0){ $res=highlight_string($str,true); }else{ $res='文件中没有内容'; } } return $res;}
本文来自内存溢出网,php教程栏目,欢迎学习! 总结
以上是内存溢出为你收集整理的php开发一个文件管理系统(附代码)全部内容,希望文章能够帮你解决php开发一个文件管理系统(附代码)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)