• PHP Video Tutorials

PHP - Function dir()



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

Sr.No Parameter & Description
1

directory(Required)

The directory to be opened.

Return Value

It 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 #5 Path: /var/www/ .. cgi-bin html .
php_function_reference.htm
Advertisements