X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP dir() Function

PHP Directory PHP Directory Reference

Example

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 #2
Path: /etc/php
filename: .
filename: ..
filename: ajax.gif
filename: books.xml
filename: cdcatalog.xml
filename: cd_catalog.xml
filename: default.asp
filename: demo_array.asp
filename: demo_array.htm
...
...
...


Definition and Usage

The dir() function returns an instance of the Directory class. This function is used to read a directory, which includes the following:

  • The given directory is opened
  • The two properties handle and path of dir() are available
  • Both handle and path properties have three methods: read(), rewind(), and close()

Syntax

dir(directory,context);

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

Technical Details

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


PHP Directory PHP Directory Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook