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



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/php/function-reference/opendir.php