头像

PHP 遍历文件夹里面所有文件

2018-05-22 14:07:37 浏览()   来源:http://www.phpdaima.com//jsfx-71.html   评论 ( 0 )   

/**
 * 遍历文件夹
 * @param string $dir
 * @param boolean $all  true表示递归遍历
 * @return array
 */
public static function scanfDir($dir='', $all = false, &$ret = array()){    
    if ( false !== ($handle = opendir ( $dir ))) {
        while ( false !== ($file = readdir ( $handle )) ) {
            if (!in_array($file, array('.', '..', '.git', '.gitignore', '.svn', '.htaccess', '.buildpath','.project'))) {
                $cur_path = $dir . '/' . $file;
                if (is_dir ( $cur_path )) {
                    $ret['dirs'][] =$cur_path;
                    $all && self::scanfDir( $cur_path, $all, $ret);
                } else {                        
                    $ret ['files'] [] = $cur_path;
                }
            }               
        }
        closedir ( $handle );
    }
    return $ret;        
}


标签: php
广告不存在
评论0

后面还有条评论,点击查看>>

温馨提示:为规范评论内容,垃圾评论一律封号...