在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
// $path : path to browse // $maxdepth : how deep to browse (-1=unlimited) // $mode : "FULL"|"DIRS"|"FILES" // $d : must not be defined function searchdir ( $path , $maxdepth = -1 , $mode = "FULL" , $d = 0 ) { if ( substr ( $path , strlen ( $path ) - 1 ) != '/' ) { $path .= '/' ; } $dirlist = array () ; if ( $mode != "FILES" ) { $dirlist[] = $path ; } if ( $handle = opendir ( $path ) ) { while ( false !== ( $file = readdir ( $handle ) ) ) { if ( $file != '.' && $file != '..' ) { $file = $path . $file ; if ( ! is_dir ( $file ) ) { if ( $mode != "DIRS" ) { $dirlist[] = $file ; } } elseif ( $d >=0 && ($d < $maxdepth || $maxdepth < 0) ) { $result = searchdir ( $file . '/' , $maxdepth , $mode , $d + 1 ) ; $dirlist = array_merge ( $dirlist , $result ) ; } } } closedir ( $handle ) ; } if ( $d == 0 ) { natcasesort ( $dirlist ) ; } return ( $dirlist ) ; }
DirectoryIterator和RecursiveDirectoryIterator php5中的目录迭代类 DirectoryIterator获取指定目录的文件或者目录. RecursiveDirectoryIterator 获取目录下所有的文件,包括子目录 -------------------------------------------------------------------------------------------------- $it = new RecursiveDirectoryIterator("./protected"); foreach(new RecursiveIteratorIterator($it) as $file) {echo $file . "<br>";} ------------------------------------------------------------------------------------------------------------ $path = "./protected/controllers/"; $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); -------------------------------------------------------------------------------------------------------------- |
2022-07-30
2022-08-18
2022-08-18
2022-08-30
2022-08-16
请发表评论