使用 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 类的实例。该函数用于读取一个目录,其中包括以下内容:
dir(
directory,
context)
Parameter | Description |
---|---|
directory | Required. Specifies the directory to open |
context | Optional. |
返回值: | Directory 类的实例。失败时为 FALSE |
---|---|
PHP 版本: | 4.0+ |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!