PHP/File Directory/readdir

Материал из Web эксперт
Перейти к: навигация, поиск

Listing the Contents of a Directory with readdir()

   <source lang="html4strict">

<html> <head> <title>Listing the Contents of a Directory with readdir()</title> </head> <body>

<?php $dirname = "."; $dh = opendir( $dirname ); while ( ! is_bool( $file = readdir( $dh )) ) {

 if ( is_dir( "$dirname/$file" ) ) {
   print "(D) ";
 }
 print "$file
";

} closedir( $dh ); ?>

</body> </html>

 </source>
   
  


Procedural directory iteration

   <source lang="html4strict">

<?php $d = opendir("/usr/local/images") or die($php_errormsg); while (false !== ($f = readdir($d))) {

   print $f . "\n";

} closedir($d); ?>

 </source>
   
  


readdir.php

   <source lang="html4strict">

<?php

  $dh = opendir("/usr/local/apache2/htdocs/");
  while ($file = readdir($dh))
     echo "$file 
"; closedir($dh);

?>

 </source>