PHP dir() Function

Definition

The dir() function returns an instance of the Directory class.

Syntax

PHP dir() Function has the following syntax.

dir(directory,context);

Parameter

ParameterIs RequiredDescription
directoryRequired.Directory to open
contextOptional.Context to use

Return

PHP dir() Function returns an instance of the Directory class. FALSE on failure.

Example

Use the dir() function to read a directory:


<?php /*from  w ww  .j av  a2  s  . c  o m*/
$d = dir(getcwd());

echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";

while (($file = $d->read()) !== false){ 
  echo "filename: " . $file . "\n"; 
} 
$d->close(); 
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions