format_bytes has moved

This commit is contained in:
bohwaz 2022-10-10 15:20:41 +02:00
parent d9986c5434
commit b8fd51c750
3 changed files with 21 additions and 4 deletions

View file

@ -1,5 +1,5 @@
Options -Indexes -Multiviews Options -Indexes -Multiviews
DirectoryIndex disabled DirectoryIndex index.php
RewriteEngine On RewriteEngine On
RewriteBase / RewriteBase /

View file

@ -61,3 +61,19 @@ function html_foot(): void
</body> </body>
</html>'; </html>';
} }
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;
}
}

View file

@ -19,9 +19,9 @@ if (!$user) {
$quota = $users->quota($user); $quota = $users->quota($user);
$server = new Server; $server = new Server;
$free = $server->format_bytes($quota->free); $free = format_bytes($quota->free);
$used = $server->format_bytes($quota->used); $used = format_bytes($quota->used);
$total = $server->format_bytes($quota->total); $total = format_bytes($quota->total);
$www_url = WWW_URL; $www_url = WWW_URL;
html_head('My files'); html_head('My files');
@ -32,6 +32,7 @@ echo <<<EOF
<dd><a href="{$user->dav_url}"><tt>{$user->dav_url}</tt></a> (click to manage your files from your browser)</dd> <dd><a href="{$user->dav_url}"><tt>{$user->dav_url}</tt></a> (click to manage your files from your browser)</dd>
<dt>NextCloud URL</dt> <dt>NextCloud URL</dt>
<dd><tt>{$www_url}</tt></dd> <dd><tt>{$www_url}</tt></dd>
<dd class="help">Use this URL to setup a NextCloud or ownCloud client to access your files.</dd>
<dt>Quota</dt> <dt>Quota</dt>
<dd>Used {$used} out of {$total} (free: {$free})</dd> <dd>Used {$used} out of {$total} (free: {$free})</dd>
</dl> </dl>