Index: t3lib/class.t3lib_foldertree.php =================================================================== --- t3lib/class.t3lib_foldertree.php (revision 7249) +++ t3lib/class.t3lib_foldertree.php (working copy) @@ -248,7 +248,7 @@ function getFolderTree($files_path, $depth=999, $depthData='', $type='') { // This generates the directory tree - $dirs = t3lib_div::get_dirs($files_path); + $dirs = t3lib_div::get_dirs($files_path, 1); $c=0; if (is_array($dirs)) { @@ -256,7 +256,6 @@ $HTML=''; $a=0; $c=count($dirs); - sort($dirs); foreach($dirs as $key => $val) { $a++; Index: t3lib/class.t3lib_div.php =================================================================== --- t3lib/class.t3lib_div.php (revision 7249) +++ t3lib/class.t3lib_div.php (working copy) @@ -3095,18 +3095,35 @@ * Usage: 11 * * @param string Path to list directories from + * @param string $order is sorting: 1= sort alphabetically, 'mtime' = sort by modification time. * @return array Returns an array with the directory entries as values. If no path, the return value is nothing. */ - public static function get_dirs($path) { + public static function get_dirs($path, $order='') { if ($path) { if (is_dir($path)) { $dir = scandir($path); + $sortarray = array(); $dirs = array(); foreach ($dir as $entry) { if (is_dir($path . '/' . $entry) && $entry != '..' && $entry != '.') { - $dirs[] = $entry; + $dirs[$entry] = $entry; + if ($order == 'mtime') { + $sortarray[$entry] = filemtime($path . '/' . $entry); + } elseif ($order) { + $sortarray[$entry] = $entry; + } } } + + // Sort them: + if ($order) { + natcasesort($sortarray); + $newArr = array(); + foreach ($sortarray as $k => $v) { + $newArr[$k] = $dirs[$k]; + } + $dirs = $newArr; + } } else { $dirs = 'error'; } @@ -3133,33 +3150,38 @@ $path = rtrim($path, '/'); // Find files+directories: - if (@is_dir($path)) { + if (@is_dir($path)) { $extensionList = strtolower($extensionList); $d = dir($path); - if (is_object($d)) { - while($entry=$d->read()) { - if (@is_file($path.'/'.$entry)) { + if (is_object($d)) { + while($entry = $d->read()) { + if (@is_file($path . '/' . $entry)) { $fI = pathinfo($entry); - $key = md5($path.'/'.$entry); // Don't change this ever - extensions may depend on the fact that the hash is an md5 of the path! (import/export extension) - if ((!strlen($extensionList) || self::inList($extensionList,strtolower($fI['extension']))) && (!strlen($excludePattern) || !preg_match('/^'.$excludePattern.'$/',$entry))) { - $filearray[$key]=($prependPath?$path.'/':'').$entry; - if ($order=='mtime') {$sortarray[$key]=filemtime($path.'/'.$entry);} - elseif ($order) {$sortarray[$key]=$entry;} + $key = md5($path . '/' . $entry); // Don't change this ever - extensions may depend on the fact that the hash is an md5 of the path! (import/export extension) + if ((!strlen($extensionList) || self::inList($extensionList,strtolower($fI['extension']))) && (!strlen($excludePattern) || !preg_match('/^' . $excludePattern . '$/', $entry))) { + $filearray[$key] = ($prependPath?$path . '/' : '') . $entry; + if ($order == 'mtime') { + $sortarray[$key] = filemtime($path . '/' . $entry); + } elseif ($order) { + $sortarray[$key] = $entry; + } } } } $d->close(); - } else return 'error opening path: "'.$path.'"'; + } else { + return 'error opening path: "' . $path . '"'; + } } // Sort them: if ($order) { - asort($sortarray); - $newArr=array(); + natcasesort($sortarray); + $newArr = array(); foreach ($sortarray as $k => $v) { - $newArr[$k]=$filearray[$k]; + $newArr[$k] = $filearray[$k]; } - $filearray=$newArr; + $filearray = $newArr; } // Return result Index: typo3/class.filelistfoldertree.php =================================================================== --- typo3/class.filelistfoldertree.php (revision 7249) +++ typo3/class.filelistfoldertree.php (working copy) @@ -359,10 +359,8 @@ function getFolderTree($files_path, $depth=999, $type='') { // This generates the directory tree - $dirs = t3lib_div::get_dirs($files_path); + $dirs = t3lib_div::get_dirs($files_path, 1); if (!is_array($dirs)) return 0; - - sort($dirs); $c = count($dirs); $depth = intval($depth);