Use the dir() function:
<?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(); ?>result:
Handle: Resource id #2Path: /etc/phpfilename: .filename: ..filename: ajax.giffilename: books.xmlfilename: cdcatalog.xmlfilename: cd_catalog.xmlfilename: default.htmlfilename: demo_array.htmlfilename: demo_array.htm.... .....The dir() function returns an instance of the Directory class. This function is used to read a directory, including the following:
The given directory to open
The handle and path attributes of dir() are available
The handle and path attributes have three methods: read(), rewind() and close()
dir( directory,context );
parameter | describe |
---|---|
directory | Required. Specifies the directory to open. |
context | Optional. |
Return value: | Returns an instance of the Directory class. Returns FALSE on failure. |
---|---|
PHP version: | 4.0+ |