diff --git a/app/FileManager.php b/app/FileManager.php index 667fb8b..c1be3b6 100644 --- a/app/FileManager.php +++ b/app/FileManager.php @@ -21,10 +21,14 @@ class FileManager { $results = []; + $directories = []; + + $files = []; + // getting files from directory - $files = scandir($path); + $items = scandir($path); - foreach($files as $file) { + foreach($items as $file) { // ignore parent directories if ($file === '.' || $file === '..') { @@ -44,9 +48,26 @@ class FileManager if ($result['is_file']) { $result['size'] = $this->formatBytes($meta['size']); + $files[] = $result; + } else { + $directories[] = $result; } + } - $results[] = $result; + usort($directories, function($a, $b) { + if (strtolower($a['filename']) < strtolower($b['filename'])) { + return 0; + } else { + return 1; + } + }); + + foreach($directories as $directory) { + $results[] = $directory; + } + + foreach($files as $file) { + $results[] = $file; } return $results; diff --git a/resources/js/components/filemanager/filemanager.riot b/resources/js/components/filemanager/filemanager.riot index adf2075..45a6e92 100644 --- a/resources/js/components/filemanager/filemanager.riot +++ b/resources/js/components/filemanager/filemanager.riot @@ -72,7 +72,8 @@ /** * - * + * + * */ files() { axios.get('/api/file/' + this.props.id, {