【PHP】打开文件路径的所有文件

小破孩
2023-07-20 / 0 评论 / 107 阅读 / 正在检测是否收录...
<?php
function open_dir($path)
{
    if (!is_dir($path) || empty($path)) die("该" . $path . "不是目录");

    $path     = $path . '/';
    $fileList = [];
    $dirFile  = scandir($path);

    if (!empty($dirFile) && is_array($dirFile)) {
        foreach ($dirFile as $file) {
            if ($file != '.' && $file != '..') {
                $fullPath = $path . $file;

                if (is_dir($fullPath)) {
                    // 子文件夹,进行递归
                    $fileList[$file] = open_dir($fullPath);
                } else {
                    //根目录下的文件
                    $fileList[] = $file;
                }
            }
        }
    }

    return $fileList;
}

$list = open_dir("/www/wwwroot/8688web.com/one");
// echo '<pre>';
// print_r($list);
// echo '</pre>';
?>
0

评论 (0)

取消