加入收藏 | 设为首页 | 会员中心 | 我要投稿 甘南站长网 (https://www.0941zz.com/)- 科技、行业物联网、开发、云计算、云管理!
当前位置: 首页 > 编程开发 > PHP > 正文

php简单文件管理器

发布时间:2023-02-16 12:33:23 所属栏目:PHP 来源:互联网
导读:代码: html head title文件管理/title Meta charset=utf-8 / /head body ?PHP //定义要查看的目录 $dir=/; //先判断$_GET[a]是否已经传值 防止NOTICE错误 if(isset($_GET[a])){ //选择判断要执行的操作 switch($_GET[a]){ case creat: //新建文件 $filename
  代码:
 
  <html>
 
      <head>
 
          <title>文件管理</title>
 
          <Meta charset='utf-8' />
 
      </head>
 
      <body>
 
          <?PHP
 
              //定义要查看的目录
 
              $dir="/";
 
              
 
              //先判断$_GET['a']是否已经传值 防止NOTICE错误
 
              if(isset($_GET['a'])){
 
                  //选择判断要执行的操作
 
                  switch($_GET['a']){
 
                      case 'creat':
 
                          //新建文件
 
                          $filename=$_POST["filename"];
 
                          $filename=rtrim($dir,"/")."/".$filename;
 
                          //写入文件 写入一个空字符串
 
                          file_put_contents($filename,"");
 
                          break;
 
                      case 'del':
 
                          //删除文件
 
                          unlink($_GET['filename']);
 
                          break;
 
                      case 'update':
 
                          //修改文件
 
                          file_put_contents($_POST['filename'],$_POST['content']);
 
                          echo "修改成功";
 
                          header("refresh:1;url=index.PHP");
 
                          break;
 
                  }
 
              }
 
              
 
          ?>
 
          <center>
 
              <h1>文件管理</h1>
 
              <form action='index.PHP?a=creat' method='post'>
 
                  文件:<input type='text' name='filename' />
 
                  <input type='submit' value='新建' />
 
              </form>
 
              <table border='1' width='900' cellpadding='5' cellspacing='0'>
 
                  <tr>
 
                      <th>文件名</th>
 
                      <th>类型</th>
 
                      <th>大小</th>
 
                      <th>创建时间</th>
 
                      <th>操作</th>
 
                  </tr>
 
                  <?PHP
 
                      //遍历目录
 
                      $dd=opendir($dir);
 
                      while(false !== ($f=readdir($dd))){
 
                          //过滤点
 
                          if($f == "." || $f == ".."){
 
                              continue;

(编辑:甘南站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读