프로그램 개발서

함수 모음 본문

PHP

함수 모음

rairen 2023. 6. 29. 16:09

1. directory_map();

코드이그나이터3에서 사용되던 함수로 특정 경로의 폴더와 파일들 목록 함수 얻기용으로 가져다 쓰기 좋아서 유용하게 사용 중

if ( ! function_exists('directory_map') ) {
	function directory_map($directory_path, $directory_depth = 0, $hidden = false) {
    	if ( $fp = @opendir($directory_path) ) {
        	$file_data = array();
            $new_depth = $directory_depth - 1;
            $directory_path = rtrim($directory_path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
            while ( false !== ( $file = readdir($fp) ) ) {
            	if ( $file === '.' or $file === '..' or ($hidden === false && $file[0] === '.') ) {
                	continue;
                }
                is_dir($directory_path . $file) && $file .= DIRECTORY_SEPARATOR;
                if (($directory_depth < 1 or $new_depth > 0) && is_dir($directory_path . $file)){
                	$file_data[$file] = directory_map($directory_path . $file, $new_depth, $hidden);
                }
                else {
                	$file_data[] = $file;
                }
            }
            closedir($fp;
            return $file_data;
        }
        return false;
    }
}

 

반응형

'PHP' 카테고리의 다른 글

[phpDocumentor]@version  (0) 2023.12.06
[phpDocumentor]@abstract  (0) 2023.12.06
JSON 결과 나오지 않을 때  (0) 2022.08.31
usable_email : 사용가능한 이메일인지 확인  (0) 2022.08.21
[PHP] phpoffice spreadsheet 읽기  (0) 2021.09.02