PHP/File Directory/scandir

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

Listing All Files in the Current Directory

   <source lang="html4strict">

<?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] . "
"; } } } } else { echo "Sorry, this directory does not exist."; } } echo numfilesindir ("sample1");

?>

 </source>
   
  


scandir.php

   <source lang="html4strict">

<?php

  print_r(scandir("/usr/local/apache2/htdocs"));

?>

 </source>
   
  


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

   <source lang="html4strict">

<?

   $files = scandir(".", 1);
   var_dump($files);

?>

 </source>