php获取文件夹文件
https://blog.csdn.net/niedewang/article/details/80875510
/**
* 使用scandir 遍历目录
*
* @param $path
* @return array
*/
function getDir($path)
{
//判断目录是否为空
if(!file_exists($path)) {
return [];
}
$files = scandir($path);
$fileItem = [];
foreach($files as $v) {
$newPath = $path .DIRECTORY_SEPARATOR . $v;
if(is_dir($newPath) && $v != '.' && $v != '..') {
$fileItem = array_merge($fileItem, getDir($newPath));
}else if(is_file($newPath)){
$fileItem[] = $newPath;
}
}
return $fileItem;
}
/**
* 使用glob 遍历
* @param $path
*/
function getDir2($path)
{
//判断目录是否为空
if(!file_exists($path)) {
return [];
}
$fileItem = [];
//切换如当前目录
chdir($path);
foreach(glob('*') as $v) {
$newPath = $path . DIRECTORY_SEPARATOR . $v;
if(is_dir($newPath)) {
$fileItem = array_merge($fileItem,getDir2($newPath));
}else if(is_file($newPath)) {
$fileItem[] = $newPath;
}
}
return $fileItem;
}

浙公网安备 33010602011771号