توابع dir() در PHP
مثال
از استفاده از توابع dir():
<?php $d = dir(getcwd()); echo ".پشتیبان: " . $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: index.asp filename: demo_array.asp filename: demo_array.htm ... ... ...
定义和用法
dir()函数返回Directory类的实例。该函数用于读取一个目录,包含如下:
给定的要打开的目录 dir()的handle和path两个属性是可用的 handle和path属性有三个方法:read()、rewind()和close()语法
dir(directory,context);
参数 | 描述 |
---|---|
directory | 必需。规定要打开的目录。 |
context | 可选。 |
技术细节
返回值: | 返回Directory类的实例。若失败则返回FALSE。 |
---|---|
PHP版本: | 4.0+ |