PHP readdir()関数
例
imagesディレクトリ内のすべてのエントリを一覧表示してから、以下を閉じます。
<?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
定義と使用法
readdir()関数は、ディレクトリ内の次のエントリの名前を返します。
構文
readdir(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 |
技術的な詳細
戻り値: | 成功した場合はエントリ名(ファイル名)、失敗した場合はFALSE |
---|---|
PHPバージョン: | 4.0以降 |
❮PHPディレクトリリファレンス