Thursday, 26 May 2011

dir()

The dir() function opens a directory handle and returns an object. The object contains three methods called read() , rewind() , and close() .
This function returns a directory stream on success and FALSE and an error on failure. You can hide the error output by adding an '@' in front of the function name.

Syntax

dir(directory)

<?php
$dir = dir("images");

while (($file = $dir->read()) !== false)
{
echo "filename: " . $file . "<br />";
}

$dir->close();
?>
<?php
//Open images directory
$dir = @ dir("images");

//List files in images directory
while (($file = $dir->read()) !== false)
  {
  echo "filename: " . $file . "<br />";
  }

$dir->close();
?> 

No comments:

Post a Comment