diff --git a/app/FileManager.php b/app/FileManager.php index c1be3b6..f88787f 100644 --- a/app/FileManager.php +++ b/app/FileManager.php @@ -47,25 +47,23 @@ class FileManager ]; if ($result['is_file']) { - $result['size'] = $this->formatBytes($meta['size']); + $result['meta']['size'] = $this->formatBytes($meta['size']); $files[] = $result; } else { $directories[] = $result; } } - usort($directories, function($a, $b) { - if (strtolower($a['filename']) < strtolower($b['filename'])) { - return 0; - } else { - return 1; - } - }); + // sorting by filename + usort($directories, [$this, 'sortByFilename']); + usort($files, [$this, 'sortByFilename']); + // adding directories foreach($directories as $directory) { $results[] = $directory; } + // adding files foreach($files as $file) { $results[] = $file; } @@ -73,6 +71,19 @@ class FileManager return $results; } + /** + * sorting by filename, function for usort + * + */ + private function sortByFilename($a, $b) + { + if (strtolower($a['filename']) < strtolower($b['filename'])) { + return 0; + } else { + return 1; + } + } + /** * * @param [type] $size [description]