PHP opendir() 함수
예시
디렉토리를 열고 내용을 읽은 다음 닫습니다.
<?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
정의 및 사용
opendir() 함수는 디렉토리 핸들을 엽니다.
통사론
opendir(path, context)
매개변수 값
Parameter | Description |
---|---|
path | Required. Specifies the directory path to be opened |
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 오류가 발생합니다. 함수 이름 앞에 '@'를 추가하여 opendir()의 오류 출력을 숨길 수 있습니다. |
---|---|
PHP 버전: | 4.0+ |
PHP 변경 로그: | PHP 5.0: 이제 path 매개변수가 ftp:// URL 래퍼 를 지원합니다. |
❮ PHP 디렉토리 참조