Open a directory, read its contents, then close in PHP
Description
The following code shows how to open a directory, read its contents, then close.
Example
/*from w w w. j ava 2 s.c o m*/
<?php
$dir = "/images/";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
closedir($dh);
}
}
?>