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);
}
}
?>
$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
filename: dog.gif
filename: horse.gif
정의 및 사용
에서 readdir () 함수는 파일 이름으로 디렉토리를 반환합니다.
문법
readdir( dir_handle );
参数 | 描述 |
---|---|
dir_handle | 可选。指定之前由 opendir() 打开的目录句柄资源。如果该参数未指定,则使用最后一个由 opendir() 打开的链接。 |
기술 세부 사항
반환 값 : | FALSE 실패 리턴에 성공하면 파일 이름을 돌려줍니다. |
---|---|
PHP 버전 : | 4.0 이상 |
PHP 디렉토리 참조