Listing the Contents of a Directory with readdir() : readdir « File Directory « PHP






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>
  
  








Related examples in the same category

1.readdir.php
2.Procedural directory iteration