PHP dir() 関数

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

dir() 関数を使用する:

<?php
$d = dir(getcwd());

echo "Handle: " . $d->handle . "<br>";
echo "Path: " . $d->path . "<br>";

while (($file = $d->read()) !== false){
  echo "filename: " . $file . "<br>";
}
$d->close();
?>

結果:

Handle: Resource id #2
Path: /etc/php
filename: .
filename: ..
filename: ajax.gif
filename: books.xml
filename: cdcatalog.xml
filename: cd_catalog.xml
filename: default.html
filename: demo_array.html
filename: demo_array.htm
...
...
...


定義と用法

dir()関数は、Directoryクラスのインスタンスを返します。This function is used to read a directory, which includes the following:


構文

dir(directory,context);

パラメータ 説明
directory 必須。オープンするディレクトリを指定する
context 任意。

技術内容
返り値: Directoryクラスのインスタンスを返します。 失敗した場合はFALSEを返します
PHP バージョン: 4.0+

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