Zend - The PHP Company




Files and Directories

Add Code


a class to Get and Output Directories List  

Type: class
Added by: llgdholland
Entered: 24/12/2000
Last modified: 01/12/2000
Rating: - (fewer than 3 votes)
Views: 15151
A framework to get the directories list at a given path and possibly print it, core or as ht-links to each directory (useful if each contains an index.htm for ex) ... to be extended


<?php
 
class dirList
{

 var 
$oa_names//array containing names
 
var $length;


 function 
getLength ()
 {
  return 
$this->length;
 }
 function 
setLength ($fa_l)
 {
    
$this->length=$fa_l;
 }


 function 
sortList ()
 {
    
sort($this->oa_names);
 }

 function 
printListKey ($fa_key)   //print array element corresponding to a given key
 
{
   echo 
$this->oa_names[$fa_key];
 }

 function 
printListKeyLink ($fa_key)
 {
   echo 
"<a href="".$this->oa_names[$fa_key]."">".$this->oa_names[$fa_key]."</a>";
 }


 function 
printList ()
 {
  
reset ($this->oa_names);
  while (list (
$key$val) = each ($this->oa_names))
  {
    echo 
$val;
    echo 
"<br>";
  }
 }
 function 
printListLink ()
 {
  
reset ($this->oa_names);
  while (list (
$key$val) = each ($this->oa_names))
  {
    echo 
"<a href="$val">$val</a>".$key;
    echo 
"<br>";
  }
 }

 function 
dirList ($fa_path='.')
 {
        
$dr dir($fa_path);
         
//compteur
        
$i=0;
        while(
$entry=$dr->read())
        {
          if (
is_dir($entry) && ($entry!=".") && ($entry!=".."))
          {
           
$this->oa_names[$i]=$entry;
           
$i++;
          }
        }
        
$this->setLength($i);
        if (
$i>0)
        {
                
$this->sortList();
        }
 }
}
?>


Usage Example




Rate This Script





Search



This Category All Categories