PHP readdir() 함수
예시
이미지 디렉토리의 모든 항목을 나열한 다음 닫습니다.
<?php
$dir = "/images/";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
closedir($dh);
}
}
?>
결과:
filename: cat.gif
filename: dog.gif
filename: horse.gif
정의 및 사용
readdir() 함수는 디렉토리에 있는 다음 항목의 이름을 반환합니다.
통사론
readdir(dir)
매개변수 값
Parameter | Description |
---|---|
dir | Optional. Specifies the directory handle resource previously opened with opendir(). If this parameter is not specified, the last link opened by opendir() is assumed |
기술적 세부 사항
반환 값: | 성공 시 항목 이름(파일 이름), 실패 시 FALSE |
---|---|
PHP 버전: | 4.0+ |
❮ PHP 디렉토리 참조