PHP - Function dir()


Advertisements


Syntax

dirhandle bool dir ( string $directory )

Definition and Usage

The dir() function opens a directory handle and returns an object. The object contains three methods called read(), rewind(), and close().

Parameters

Parameter Description
directory Required. The directory to be opened.

Return Value

Returns directory handle on success or FALSE on failure.

Example

Following is the usage of this function −

<?php
   $d = dir("/var/www/");
   echo "Handle: " . $d->handle . "\n";
   echo "Path: " . $d->path . "\n";
   
   while (false !== ($entry = $d->read())) {
      echo $entry."\n";
   }
   $d->close();
?> 

This will produce the following result −

Handle: Resource id #2
Path: /var/www/
.
..
tutorialspoint
images
home

php_function_reference.htm

Advertisements