PHP readdir

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

PHP : readdir() function

Last update on January 25 2017 11:38:37 (UTC/GMT +8 hours)

Description

The readdir() function is used to read an entry from a directory handle opened by opendir() function.

Version

(PHP 4 and above)

Syntax

readdir(dir_handle) 

Parameter

Name

Description

Required /
Optional

Type

dir_handle

Specified directory handle, previously open by opendir().

Required

Resource.

Return value

The filename on success, or FALSE on failure.

Value Type : String.

Example :

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

  2. while (($file = readdir($dir_name)) !== false)  

  3. {  

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

  5. }  

  6. closedir($dir_name)  

  7. ?>