PHP/File Directory/readdir
Listing the Contents of a Directory with readdir()
<html>
<head>
<title>Listing the Contents of a Directory with readdir()</title>
</head>
<body>
<div>
<?php
$dirname = ".";
$dh = opendir( $dirname );
while ( ! is_bool( $file = readdir( $dh )) ) {
if ( is_dir( "$dirname/$file" ) ) {
print "(D) ";
}
print "$file<br/>";
}
closedir( $dh );
?>
</div>
</body>
</html>
Procedural directory iteration
<?php
$d = opendir("/usr/local/images") or die($php_errormsg);
while (false !== ($f = readdir($d))) {
print $f . "\n";
}
closedir($d);
?>
readdir.php
<?php
$dh = opendir("/usr/local/apache2/htdocs/");
while ($file = readdir($dh))
echo "$file <br>";
closedir($dh);
?>