获取当前目录及新建目录

原创2019-10-07 15:04:3512
摘要:<!DOCTYPE html>             <?php              //获取当前目录名 


<!DOCTYPE html>

             <?php 

             //获取当前目录名

             $dir = opendir(__DIR__);

             ?>

<html>

             <head>

                     <title>create dir</title>

                     <style type="text/css">

                     *{margin:0;padding: 0;}

                     div{margin: 30px auto;width: 400px;}

                     input{margin: 0 10px;}

                     </style>

             </head>

             <body>

             <div>

                     <form action="dir.php" method="post">

                     <p>请输入文件夹名:<input type="text" name="floder"><input type="submit" name="submit"></p>

                     </form>

             </div>

             <hr>

             <div>

                     <?php

                             while ($item = readdir($dir)) {

                                          echo '<p>'.$item.'<br></p>';

                             }

                     ?>

             </div>

             </body>

             <?php

                     //获取请求的文件名

                     @$floder = $_REQUEST['floder'];

                     //未填文件名,不操作

                     if(!empty($floder)){

                             //目录名存在就跳转到当前页面

                             if(is_dir($floder)){

                                     echo "<script>alert('目录已存在!');location.href='dir.php';</script>";

                                      return;

                             }else{

                                     mkdir($floder);

                                      header('location:dir.php');

                             }

                     }

             ?>

</html>


批改老师:欧阳克批改时间:2019-10-12 16:27:04
老师总结:完成的不错。目录文件,一般用在日志和图片上,继续加油

发布手记

热门词条

第九期线上培训班