Listing All Files in the Current Directory : scandir « File Directory « PHP





Listing All Files in the Current Directory

 
<?php

  function numfilesindir ($thedir){
    if (is_dir ($thedir)){
      $scanarray = scandir ($thedir);
      for ($i = 0; $i < count ($scanarray); $i++){
        if ($scanarray[$i] != "." && $scanarray[$i] != ".."){
          if (is_file ($thedir . "/" . $scanarray[$i])){
            echo $scanarray[$i] . "<br />";
          }
        }
      }
    } else {
      echo "Sorry, this directory does not exist.";
    }
  }
  echo numfilesindir ("sample1");

?>
  
  










Related examples in the same category

1.scandir.php
2.The scandir( ) function takes a minimum of one parameter with an optional second.