Monday, 26 August 2013

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() .

Paramters

ParameterDescription
directoryRequired. 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 following result:
Handle: Resource id #2
Path: /var/www/
.
..
tutorialspoint
images
home

No comments:

Post a Comment