PHP dir

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

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 :

  1. $dir_name = dir("test");  

  2. while (($file = $dir_name->read()) !== false)  

  3. {  

  4. echo "filename: " . $file . "
    ";  

  5. }  

  6. $dir_name->close();  

  7. ?>  

Output :

filename: .
filename: ..