Add human bytes conversion with maximum size (#7)

This commit is contained in:
Beu
2020-02-24 23:35:33 +01:00
parent 907d92639f
commit 2ec44d4a50
4 changed files with 18 additions and 6 deletions

View File

@ -11,6 +11,13 @@
return rmdir($dir);
}
function formatBytes($size, $precision = 2) {
$base = log($size, 1024);
$suffixes = array('', 'KB', 'MB', 'GB', 'TB');
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
}
// Check if file have to be deleted
$data_dir = array_diff(scandir(_DATA_DIR), array('..', '.', '.gitkeep'));
foreach ($data_dir as $data_dir_content)
@ -65,12 +72,12 @@
if ($filesize < _SIZE_LIMIT )
{
print($downloadurl . $rnd_data );
print($downloadurl . $rnd_data . "\n");
}
else
{
delTree(_DATA_DIR . "/" . $rnd_data);
print("File size exceeded (Max " . _SIZE_LIMIT . " bytes)");
print("File size exceeded (Max " . formatBytes(_SIZE_LIMIT) . " bytes)");
}
@ -108,7 +115,7 @@
{
if (stristr($_SERVER["HTTP_USER_AGENT"], 'curl') or stristr($_SERVER["HTTP_USER_AGENT"], 'Wget'))
{
print("To upload file:\n");
print("To upload file (max " . formatBytes(_SIZE_LIMIT) . "):\n");
print("* curl --upload-file my_file " . $uploadurl . "\n");
print("* wget -q --body-file my_file --method=PUT -O - " . $uploadurl . "\n");
print("\n");
@ -123,4 +130,4 @@
}
}
?>
?>