Added sorting and previewing capabilities to files.

This commit is contained in:
2018-06-19 01:50:29 +02:00
committed by Stefan Rohde-Enslin
parent 768c0998aa
commit 32345e9629
3 changed files with 156 additions and 27 deletions

View File

@ -1,7 +1,6 @@
<?PHP
/**
* Start page of the backend.
* Offers a dashboard.
* This script offers functionality related to uploading and deleting files.
*
* @author Joshua Ramon Enslin <joshua@jrenslin.de>
*/
@ -30,7 +29,43 @@ define("fileDir", __DIR__ . "/../files");
if ($task == "list") {
$files = scanDirConts(fileDir);
echo json_encode($files);
$output = [];
foreach ($files as $file) {
$output[] = [
"name" => $file,
"type" => mime_content_type(fileDir . "/$file"),
"size" => filesize(fileDir . "/$file"),
"mtime" => filemtime(fileDir . "/$file"),
];
}
if (isset($_GET['sort'])) {
if ($_GET['sort'] == "name") {
usort($output, function(array $a, array $b) {
return strnatcmp($a['name'], $b['name']);
});
}
else if ($_GET['sort'] == "type") {
usort($output, function(array $a, array $b) {
return strnatcmp($a['type'], $b['type']);
});
}
else if ($_GET['sort'] == "size") {
usort($output, function(array $a, array $b) {
if ($a['size'] == $b['size']) return 0;
return ($a['size'] > $b['size']) ? -1 : 1;
});
}
else if ($_GET['sort'] == "mtime") {
usort($output, function(array $a, array $b) {
if ($a['mtime'] == $b['mtime']) return 0;
return ($a['mtime'] > $b['mtime']) ? -1 : 1;
});
}
}
echo json_encode($output);
return;
}