php - Reading Directories only within another directory -


i'm attempting list folder names within selected directory. output "." , ".." code designed remove them. other there directories within test folder yet output blank page.

here code:

class diring {      private $target = '/users/matthew/documents/mdcms/public_html/templates';      private $dirs = array();      private $err = array();      function readdirs() {          if (is_dir($this->target)) {             if ($handle = opendir($this->target)) {             while (false !== ($item = readdir($handle))) {             if (is_dir($item) && $item != "." && $item != "..") {               echo $item;             }             }             closedir($handle);             }           } else {             $this->err[] = 'the directory trying access does\'nt exist. ';             $this->errs();         }      }      function errs() {          $errors = $this->err;         if (!empty($errors)) {             foreach ($errors $error) {                 echo $error;             }         }      }     } 

anybody know i'm missing, looking through documentation should need output folder names.

thanks

much easier:

if(is_dir($this->target)) {     foreach(glob($this->target . '/*', glob_onlydir) $dir) {         echo basename($dir);     } } 

another way if want maintain array of basenames:

if(is_dir($this->target)) {     $dirs = array_map('basename', glob($this->target . '/*', glob_onlydir));     foreach($dirs $dir) {         echo $dir;     } } 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -