ディレクトリをオープンし、ファイルのリストを表示し、ディレクトリハンドルをリセットし、そのファイルを再度一覧表示してクローズします:
<?php
$dir = "/images/";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
// List files in images directory
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
rewinddir();
// List once again files in images directory
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
closedir($dh);
}
}
?>
結果:
filename: cat.gif
filename: dog.gif
filename: horse.gif
filename: cat.gif
filename: dog.gif
filename: horse.gif
rewinddir() 関数は、opendir()で作成したディレクトリハンドルをリセットします。
rewinddir(dir_handle);
パラメータ | 説明 |
---|---|
dir_handle | 任意。opendir()で、前に開いたディレクトリハンドルリソースを指定する。 このパラメータを指定しないと、opendir()によって最後に開かれたリンクが仮定される |
返り値: | - |
---|---|
PHP バージョン: | 4.0+ |