+ $element
"; $folderhtml .= filesys_get_folder_tree("$path/$element"); $folderhtml .= "
\n\n"; } else { # get the size of this file in kilobytes $file_size_kb = intval(filesize($path.'/'.$element) / 1024); $folderhtml .= " + $element ($file_size_kb Kb)
\n"; } } } return $folderhtml; } ################################################ FUNCTION: filesys_dirs_present # # returns: true or false # parameters: path to directory to inspect, pattern to match directory name # against function filesys_dirs_present($path,$pattern = "/.*/") { # make sure the path passed here is really a directory we can't # check anything but a directory, since only directory will contain # other directories, duh $handle = is_dir($path) ? opendir($path) : NULL ; if(empty($handle)) { return(NULL); } # set through each child in this directory and see if the child # is directory but not the parent or current directory # readdir returns FALSE when no children are left to inspect while($child = readdir($handle) and $child !== false) { # make sure each is_dir call is not using cached information # from last is_dir check clearstatcache(); # check if this child is directory and whether it # matches the user given pattern or not if(is_dir($path.'/'.$child) and ($child !== '..') and ($child !== '.') and (preg_match($pattern,$child)) ) { # we can return true with the first matching folder we find # this is an OR operation return(true); } } # if we get here, no matching folders were found, so none exist # so we return false return(false); } ######################################### FUNCTION: filesys_get_wanted_children # # returns: array of wanted dir children # parameters: 1) path to directory; 2) command to remove [files,folders] # 3) a pattern to match folder/file names against function filesys_get_wanted_children($path,$exclude,$pattern = "/.*/") { # the cmd can be passed as either all cap or not, so conform it # here to lower case $exclude = strtolower($exclude); # fill an array full of the directory children, but only, of course if # the passed path is really to a directory $children = is_dir($path) ? scandir($path) : NULL ; if(empty($children)) { return(NULL); } # remove the current and parent directories $children = preg_grep("/^\.{1,2}$/",$children,PREG_GREP_INVERT); # get only the children that match the pattern $children = preg_grep($pattern,$children); # if files are to be removed, remove them if($exclude == 'files') { foreach($children as $key => $value) { if(!is_dir($path.'/'.$value)) unset($children[$key]); } } # if folders are to be removed, remove them else if($exclude == 'folders') { foreach($children as $key => $value) { if(is_dir($path.'/'.$value)) unset($children[$key]); } } # return the array of directory children, free of the bad little ones return($children); } ?>