PHP/File Directory/opendir

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

Listing directory

 
<?php   
  $dirname = "C:\\Apache\\bin";

  $dir = opendir( $dirname );
  
  while( false != ( $file = readdir( $dir ) ) )
  {
    if( ( $file != "." ) and ( $file != ".." ) )
    {
      $file_list .= "<li>$file</li>";
    }
  }
  closedir( $dir );
?>
<html>
 <head>
  <title>Listing directory</title>
 <head>
 <body>
  <p>Files in <?php echo( $dirname ); ?> </p>
  <ul>
    <?php echo( $file_list ); ?>
  </ul>
 </body>
</html>



Reading a Directory Listing Using opendir()

 
<?php
     $dr = @opendir("/tmp/");
     if(!$dr) {
          echo "Error opening the /tmp/ directory!<BR>";
          exit;
     }
     while(($files[] = readdir($dr)) !== false);
     print_r($files);
?>