0715PHP练习:文件操作

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <script src="../0622/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<style type="text/css">
    li{
        height: 20px;
        width: 100px;
        background-color: lightslategrey;
        border: 1px solid gainsboro;
    }
    li:hover{
        cursor: pointer;
    }
    .wjj{
        height: 20px;
        width: 100px;
        background-color: goldenrod;
        border: 1px solid gainsboro;
    }
</style>
<body>
    <?php
        $lujing = empty($_GET['lj'])?"../bootstrap":$_GET['lj'];
        //第一次打开获取不到传值,定义文件的开始路径
        $fj = dirname($lujing);
        //找到当前路径的父级路径
        $fj = ($fj == ".")?"..":$fj;
        //当父级路径是当前路径(.)时,改为根目录(..)
        $ziyuan = opendir($lujing);
        //打开文件夹路径获取资源
        echo "<ul><li class='wjj' bs='$fj'>返回</li>";
        while($nr = readdir($ziyuan)){
            //读取资源
            if($nr == '.' || $nr == '..') continue;
            //跳过当前路径和根目录
            if(is_dir("{$lujing}/{$nr}")){
                //区分文件夹和文件
                echo "<li class = 'wjj' bs = '{$lujing}/{$nr}'>".$nr."</li>";
            }else{
                echo "<li>".$nr."</li>";
            }
        }
        echo "</ul>";
        closedir();
        //关闭文件夹
    ?>
</body>
</html>
<script type="text/javascript">
    $(".wjj").click(function(){
        var lj = $(this).attr("bs");
        window.location.href = "wenjian.php?lj="+lj;
        //点击时刷新页面并传值,改变路径
    })
</script>

猜你喜欢

转载自www.cnblogs.com/zhangbaozhong/p/9314813.html