php文件夹内文件递归获取
2022-6-5 夙夜 实际技能
function readFolderFiles($path)
{
$list = [];
$resource = opendir($path);
while ($file = readdir($resource))
{
//排除根目录
if ($file != ".." && $file != ".")
{
if (is_dir($path . "/" . $file))
{
//子文件夹,进行递归
$list[$file] = readFolderFiles($path . "/" . $file);
}
else
{
//根目录下的文件
$list[] = $file;
}
}
}
closedir($resource);
return $list ? $list : [];
}
标签: php