w3resource

PHP: dir() function

Description

The dir() function is a mechanism to read a dir, which includes following :
1. The given directory is open.
2. Two properties (handle and path) of the dir are available.
3. Both handle and path properties have three methods read(), rewind() and close().
4. The path property set the path of the directory.

Version:

(PHP 4 and above)

Syntax:

dir(dir_name)

Parameter:

Name Description Required /
Optional
Type
dir_name The directory name. Required String

Return value:

An object.

Example:

<?php
$dir_name = dir("test");
while (($file = $dir_name->read()) !== false)
{
echo "filename: " . $file . "<br />";
}
$dir_name->close();
?>

Sample Output:

filename: .
filename: .. 

View the example in the browser
See also

PHP Function Reference

Previous: chroot
Next: closedir



Follow us on Facebook and Twitter for latest update.