PHP - Function opendir()


Advertisements


Syntax

resource opendir ( string $path [, resource $context] );

Definition and Usage

Opens up a directory handle to be used in subsequent closedir(), readdir(), and rewinddir() calls.

Parameters

Parameter Description
path Required. The directory path that is to be opened
context Optional. Specifies the context of the directory handle. Context is a set of options that can modify the behavior of a stream.

Return Value

Returns a directory handle resource on success, or FALSE on failure.

Example

Following is the usage of this function −

<?php
   //Open images directory
   $dir = opendir("/var/www/images");
   
   //List files in images directory
   while (($file = readdir($dir)) !== false)
   {
      echo "filename: " . $file . "<br />";
   }
   closedir($dir);
?> 

This will produce the following result −

filename: .
filename: ..
filename: logo.gif
filename: mohd.gif

php_function_reference.htm

Advertisements