opendir
(PHP 3, PHP 4, PHP 5)
opendir -- ディレクトリ・ハンドルのオープン
説明
resource
opendir ( string path )
ディレクトリ・ハンドルをオープンします。この関数は、この後、
closedir(), readdir(),
rewinddir() 関数コールで使用されます。
path が有効なディレクトリでないかまたは権
限が制限されているかファイルシステムのエラーによりディレクトリが
オープンできない場合、opendir()はFALSEを返し、
E_WARNINGエラーが発行されます。
opendir()のこのエラー出力は、
関数名の前に '@'
を付けることにより抑制できます。
例 1. opendir() の例
<?php $dir = "/tmp/";
// Open a known directory, and proceed to read its contents if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { print "filename: $file : filetype: " . filetype($dir . $file) . "\n"; } closedir($dh); } } ?>
|
|
PHP 4.3.0以降、pathは
ディレクトリのリスト表示をサポートするURLにすることもできます。
ただしPHP 4.3においてはfile://
URLラッパだけがサポートしています。
PHP 5.0.0はftp://URLラッパをもサポートします。
is_dir(),
readdir(),
Dirも参照してください。