From 2ec44d4a50dc7091a03498f951ac804666b02f79 Mon Sep 17 00:00:00 2001 From: Beu Date: Mon, 24 Feb 2020 23:35:33 +0100 Subject: [PATCH] Add human bytes conversion with maximum size (#7) --- conf/config.sample.php | 2 +- front.php | 4 +++- index.php | 15 +++++++++++---- style.css | 3 +++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/conf/config.sample.php b/conf/config.sample.php index 76567d1..e3343d3 100644 --- a/conf/config.sample.php +++ b/conf/config.sample.php @@ -3,6 +3,6 @@ define('_HTTP_PROTO','http'); define('_HTTP_DOMAIN','localhost:8080'); // domain/IP with port if needed define('_HTTP_PATH','/'); - define('_SIZE_LIMIT','2000000'); // in bytes + define('_SIZE_LIMIT','2097152'); // in bytes define('_PRETTY_URL', false); // Based on htaccess ?> \ No newline at end of file diff --git a/front.php b/front.php index 06684b4..87fb7df 100644 --- a/front.php +++ b/front.php @@ -24,13 +24,15 @@
Drag and Drop your file or +
+(Maximum )



This tool is usable with curl or wget.

-To upload file:
+To upload file (max ):
  • curl --upload-file ./my_file
  • wget -q --body-file='./my_file' --method=PUT -O -

    diff --git a/index.php b/index.php index e6b84a7..597884b 100644 --- a/index.php +++ b/index.php @@ -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 @@ } } -?> \ No newline at end of file +?> \ No newline at end of file diff --git a/style.css b/style.css index 1a5996c..cc262b8 100644 --- a/style.css +++ b/style.css @@ -78,3 +78,6 @@ footer a { font-weight: bold; text-decoration: none; } +small { + color: #555; +} \ No newline at end of file