PHP遍历指定目录下所有文件函数,可指定文件类
这个比 span style=font-family:Consolas, Bitstream Vera Sans Mono, Courier New, Courier, monospace;line-height:14.649999618530273px;background-color:#F8F8F8;scandir出来的好用/span
这个比
scandir出来的好用
/**
* 遍历获取目录下的指定类型的文件
* @param $path
* @param array $files
* @return array
*/
function getfiles( $path , &$files = array() )
{
if ( !is_dir( $path ) ) return null;
$handle = opendir( $path );
while ( false !== ( $file = readdir( $handle ) ) ) {
if ( $file != '.' && $file != '..' ) {
$path2 = $path . '/' . $file;
if ( is_dir( $path2 ) ) {
getfiles( $path2 , $files );
} else {
if ( preg_match( "/\.(gif|jpeg|jpg|png|bmp)$/i" , $file ) ) {
$files[] = $path2;
}
}
}
}
return $files;
}
- 上一篇:二维数组的‘分组’排序
- 下一篇:php 服务器限速代码(转载)
精彩图集
精彩文章






