diff --git a/www/.htaccess b/www/.htaccess index 7d2d4fe..7952e8b 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -1,5 +1,5 @@ Options -Indexes -Multiviews -DirectoryIndex disabled +DirectoryIndex index.php RewriteEngine On RewriteBase / diff --git a/www/_inc.php b/www/_inc.php index 9a5a2a4..995fb31 100644 --- a/www/_inc.php +++ b/www/_inc.php @@ -61,3 +61,19 @@ function html_foot(): void '; } + +function format_bytes(int $bytes, string $unit = 'B'): string +{ + if ($bytes >= 1024*1024*1024) { + return round($bytes / (1024*1024*1024), 1) . ' G' . $unit; + } + elseif ($bytes >= 1024*1024) { + return round($bytes / (1024*1024), 1) . ' M' . $unit; + } + elseif ($bytes >= 1024) { + return round($bytes / 1024, 1) . ' K' . $unit; + } + else { + return $bytes . ' ' . $unit; + } +} diff --git a/www/index.php b/www/index.php index 05cac99..dd95a66 100644 --- a/www/index.php +++ b/www/index.php @@ -19,9 +19,9 @@ if (!$user) { $quota = $users->quota($user); $server = new Server; -$free = $server->format_bytes($quota->free); -$used = $server->format_bytes($quota->used); -$total = $server->format_bytes($quota->total); +$free = format_bytes($quota->free); +$used = format_bytes($quota->used); +$total = format_bytes($quota->total); $www_url = WWW_URL; html_head('My files'); @@ -32,6 +32,7 @@ echo <<{$user->dav_url} (click to manage your files from your browser)
NextCloud URL
{$www_url}
+
Use this URL to setup a NextCloud or ownCloud client to access your files.
Quota
Used {$used} out of {$total} (free: {$free})