PHP Function: getDirectory


/ Published in: PHP
Save to your folder(s)

Returns an array of folder names contained within the passed path.


Copy this code and paste it in your HTML
  1. function getDirectory($path){
  2.  
  3. // Directories to ignore when listing output
  4. $ignore = array( 'cgi-bin', '.', '..' );
  5.  
  6. $handle = opendir($path);
  7.  
  8. $dir_arr = array();
  9. $i = 0;
  10.  
  11. while (false !== ($dir = readdir($handle))) {
  12. if( !in_array( $dir, $ignore ) ){
  13. if (is_dir("$path/$dir")) {
  14. $dir_arr[] = $dir;
  15. }
  16. }
  17. }
  18.  
  19. closedir($handle);
  20.  
  21. return $dir_arr;
  22.  
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.