PHP rewinddir() 関数

❮ PHP ディレクトリ・ リファレンス

ディレクトリをオープンし、ファイルのリストを表示し、ディレクトリハンドルをリセットし、そのファイルを再度一覧表示してクローズします:

<?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+

❮ PHP ディレクトリ・ リファレンス