本站有闲置空间

PHP目录文件查找

2020-4-12 tomeqiu 技术原创

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>文件查找</title>
    </head>
    <body>
        <form action="" method="post">
            <p>在XX目录查找XX文件</p>
            <p>目录:
            <input list="browsers" name="date">
                <datalist id="browsers">
                    <option value="202001">
                    <option value="202002">
                    <option value="202003">
                    <option value="202004">
                </datalist>
            </p>
            <p>文件:
            <input type="text" name="key" />
            </p>
            <p><input type="submit" name="sub" value=" 查 找 " /></p>
        </form>
<?php

$dir = "/data/ipcc/";   //操作系统目录
$root = "/ipcc/";       //http根目录

$date = $_POST['date'];    //子目录名
$search = $_POST['key'];   //文件名

if (is_dir($dir)) {
    if ($dh = opendir($dir)){
        $num = 0;   //计数
        while (($dirname = readdir($dh)) !== false) {
            if (strstr($dirname,$date)) {   //按关键字搜索子目录名
                $dir2=$dir.$dirname."/";    //子目录绝对路径
                if ($dh2 = opendir($dir2)){
                    while (($dirname2 = readdir($dh2)) !== false) {
                        if (strstr($dirname2,$search)) {    //按关键字搜索子目录下的文件
                            echo "<a href=$root$dirname/$dirname2>$dirname/$dirname2<a /><br />\n"; //显示文件的http全路径
                            $num = $num + 1;    //计数
                        }
                    }
                    closedir($dh2);
                }
            }
        }
        closedir($dh);
        echo "合计:$num";  //显示计数结果
    }
}
?>

    </body>
</html>

标签: php

发表评论:

Powered by emlog  数据库调用 6次 加载耗时 24.62mssitemap
Free Web Hosting