Online Shopping : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 14 people (21%) answered Yes
Recently 3 of 10 people (30%) answered Yes

Entry

how do i get a directory listing on a server without displaying any of the subdirectories?

Nov 27th, 2008 14:30
healthy man, dman, Sorin Neacsu, sanj maghera,


Assuming you want to list all the files of a direcroty without listing 
any of its subdirectories, here it is :
<?
print_r (getDirFiles("/www/apache/htdocs/")) ;              
   function getDirFiles($dirPath)
   {
      if ($dirPath[strlen($dirPath)] != "/") 
        $dirPath .= "/";
      if ($handle = opendir($dirPath)) 
      {
          while (false !== ($file = readdir($handle))) 
              if ($file != "." && $file != ".." && (!is_dir($dirPath . 
$file))) {   
                  $filesArr[] = trim($file);
              };
          closedir($handle);
      }  
      return $filesArr;     
   } 
?>
http://www.healthdothealth.com
http://www.healthxhealth.com
http://www.mesotheliomainmesothelioma.com
http://www.healthfirewall.com
http://www.flathealth.com
http://www.healthbodyguard.com