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();
?> 

chroot()

The chroot() function changes the root directory of the current process to the specified directory.
This function returns TRUE on success and FALSE on failure.

Syntax

chroot(directory)
This function does not work on Windows platforms.

chdir()

The chdir() function changes the current directory to the specified directory.
This function returns TRUE on success and FALSE on failure.

Syntax

chdir(directory)

<?php

chdir("images");
echo "<br />";
echo getcwd();
?>