/** * Utility function to read the files in a directory * @param string The file system path * @param string A filter for the names * @param boolean Recurse search into sub-directories * @param boolean True if to prepend the full path to the file name */ function extReadDirectory($path, $filter = '.', $recurse = false, $fullpath = false) { $arr = array(); if (!@is_dir($path)) { return $arr; } $handle = opendir($path); while ($file = readdir($handle)) { if (is_array($file)) { $file = $file['name']; } $dir = extPathName($path . '/' . $file, false); $isDir = @is_dir($dir); if ($file != "." && $file != "..") { if (preg_match("/{$filter}/", $file)) { if ($fullpath) { $arr[] = trim(extPathName($path . '/' . $file, false)); } else { $arr[] = trim($file); } } if ($recurse && $isDir) { $arr2 = extReadDirectory($dir, $filter, $recurse, $fullpath); $arr = array_merge($arr, $arr2); } } } closedir($handle); asort($arr); return $arr; }
function get_abs_item($dir, $item) { // get absolute file+path if (is_array($item)) { // FTP Mode $abs_item = '/' . get_abs_dir($dir)."/".$item['name']; if (get_is_dir($item)) { $abs_item.='/'; } return extPathName($abs_item); } return extPathName(get_abs_dir($dir)."/".$item); }