PHP scandir() 함수
예시
이미지 디렉토리 내의 파일 및 디렉토리 나열:
<?php
$dir = "/images/";
// Sort in ascending order - this is default
$a = scandir($dir);
// Sort in descending order
$b = scandir($dir,1);
print_r($a);
print_r($b);
?>
결과:
Array
(
[0] => .
[1] => ..
[2] => cat.gif
[3] => dog.gif
[4] => horse.gif
[5] => myimages
)
Array
(
[0] => myimages
[1] => horse.gif
[2] => dog.gif
[3] => cat.gif
[4] => ..
[5] => .
)
정의 및 사용
scandir() 함수는 지정된 디렉터리의 파일 및 디렉터리 배열을 반환합니다.
통사론
scandir(directory, order, context)
매개변수 값
Parameter | Description |
---|---|
directory | Required. Specifies the directory to be scanned |
order | Optional. Specifies the sorting order. Default sort order is alphabetical in ascending order (0). Set to SCANDIR_SORT_DESCENDING or 1 to sort in alphabetical descending order, or SCANDIR_SORT_NONE to return the result unsorted |
context | Optional. Specifies the context of the directory handle. Context is a set of options that can modify the behavior of a stream |
기술적 세부 사항
반환 값: | 성공 시 파일 및 디렉토리 배열, 실패 시 FALSE. 디렉토리가 디렉토리가 아닌 경우 E_WARNING을 던집니다. |
---|---|
PHP 버전: | 5.0+ |
PHP 변경 로그: | PHP 5.4: 주문 상수가 추가되었습니다 . |
❮ PHP 디렉토리 참조