PHP opendir

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

PHP : opendir() function

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

Description

The opendir() function is used to open a directory handle to be used by closedir(), readdir() and rewinddir() functions.

Version

(PHP 4 and above)

Syntax

opendir(path_name, context) 

Parameters

Name

Description

Required/ Optional

Type

path_name

The directory path name to be opened.

Required

string

context

Context is a set of parameters and wrapper specific option which modifies or enhances the behavior of a string.

Optional

string

Return value

A directory handle resource on success, or FALSE on failure.

Value Type : Resource

Example :

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

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

  3. {  

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

  5. }  

  6. closedir($dir_name)  

  7. ?>