w3resource

PHP: opendir() function

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:

<?php
$dir_name = opendir("test");
while (($file = readdir($dir_name)) !== false)
{
echo "filename: " . $file . "<br />";
}
closedir($dir_name)
?>

See also

PHP Function Reference

Previous: getcwd
Next: readdir



Follow us on Facebook and Twitter for latest update.