Blogroll

Thursday, February 16, 2012

List files and folders in the folder

This is easy way to read all file and folder to array, this also check allow extestion file to read.



 class fileEntity{
     public $filename=null;
   public $is_dir=null;
   public function __construct($filename, $filetype) {
       $this->filename = $filename;
         $this->is_dir =$filetype;
   }
}

function listFile($path,$array_allow_file) {  
     $result =array();
     $TrackDir=opendir($path);  
     
     while ($file = readdir($TrackDir)) {  
      
      if ($file == "." || $file == "..") { }  
      else {
            $extesion = end(explode('.', $file));
            if (in_array($extesion, $array_allow_file) ||  is_dir($path.'/'.$file))
            {
            $entity = new fileEntity($file, is_dir($path.'/'.$file));
            array_push($result, $entity);
            }
       } 
     }  
     closedir($TrackDir);  

    return $result;   
}  
Olá! Se você ainda não assinou, assine nosso RSS feed e receba nossas atualizações por email, ou siga nos no Twitter.
Nome: Email:

0 comments:

Post a Comment