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);
}
}
?>
結果:
filename: cat.gif
filename: dog.gif
filename: horse.gif
定義と使用法
closedir()関数は、ディレクトリハンドルを閉じます。
構文
closedir(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 |
技術的な詳細
戻り値: | - |
---|---|
PHPバージョン: | 4.0以降 |
❮PHPディレクトリリファレンス