Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP dir() Function

PHP dir() Function

PHP Directory PHP Directory Reference Manual

Example

Using the dir() function:

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

Result:

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

...

...

...


Definition and Usage

The dir() function returns an instance of the Directory class. It is used to read a directory, as follows:


Syntax

dir(

directory,context

);

Parameters Description
directory Required. Specifies the directory to open.
context Optional.

Technical Details

Return Value: Returns an instance of the Directory class, or FALSE on failure.
PHP Version: 4.0+

PHP Directory PHP Directory Reference Manual