PHP closedir()関数
例
ディレクトリを開いて、その内容を読み取り、閉じます:
<?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
定義と使用法
closedir() 関数はディレクトリハンドルを閉じます。
構文
closedir(dir_handle);
| パラメータ | 説明 |
|---|---|
| dir_handle | オプション。指定するのは、以前にopendir()opendir() で開かれたディレクトリハンドルリソース。このパラメータが指定されない場合、最後に opendir() で開かれたリンクが使用されます。 |
技術詳細
| 戻り値: | - |
|---|---|
| PHP バージョン: | 4.0+ |
PHP Directory リファレンスマニュアル その他の拡張