home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / filenames.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  1.0 KB  |  35 lines

  1. <? 
  2. /* 
  3.  
  4. This script read the filenames from a specified directory and returns them in an array. 
  5. The number of filenames is also returned. 
  6.  
  7. Copyleft(L) 1999 Eric Persson, eric@persson.tm, http://www.persson.tm/scripts/ 
  8.  
  9. */ 
  10.  
  11. Function searchdir($basedir) 
  12. global $filelisting, $number;  //defines the two variables as global so they can be accessed from outside the function 
  13.     unset($filelisting);  //kills $filelisting in case it have been used earlier in the script 
  14.     unset($number);  //same as above 
  15.     $handle=opendir($basedir); 
  16.         while ($file = readdir($handle)) { 
  17.             if ($file== "." or $file== "..") { 
  18.             } else { 
  19.             $filelisting[]= "$basedir$file"; 
  20.             }; 
  21.         }; 
  22.  
  23.     $number=sizeof($filelisting);  //gets the size of the array 
  24. }; 
  25.  
  26.  
  27. searchdir( "./");  //runs the function to search the current directory 
  28. echo $filelisting[1];  //echos the second value in the array 
  29. echo $number;  //echos the size of the array 
  30.  
  31.  
  32.  
  33. ?> 
  34.