From 73fed1269ec265beb0cc062101c5b8f3d6d1c73c Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 26 Mar 2018 15:04:55 +0200 Subject: [PATCH] removed bcmath requirement --- tools/backblaze_upload.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tools/backblaze_upload.php b/tools/backblaze_upload.php index ae40739..fdc3c67 100644 --- a/tools/backblaze_upload.php +++ b/tools/backblaze_upload.php @@ -5,7 +5,6 @@ * This tool uploads all local images to backblaze if they don't exist yet * You can use this to backup your images to backblaze or set it up as your data source for scaling * -* This scripts needs the "bcmath" library. install it with: apt-get install php-bcmath */ if(php_sapi_name() !== 'cli') exit('This script can only be called via CLI'); @@ -59,17 +58,20 @@ foreach($localfiles as $hash) if($sim!==true) $b->upload($hash); $uploadsize+=filesize($dir.$hash.DS.$hash); - echo " done.\tUploaded so far: ".renderSize($uploadsize,2,false)."\n"; + echo " done.\tUploaded so far: ".renderSize($uploadsize)."\n"; } } +function renderSize($bytes, $precision = 2) { + $units = array('B', 'KB', 'MB', 'GB', 'TB'); -function renderSize($byte,$precision=2,$mibi=true) -{ - $base = (string)($mibi?1024:1000); - $labels = array('K','M','G','T','P','E','Z','Y'); - for($i=8;$i>=1;$i--) - if(bccomp($byte,bcpow($base, $i))>=0) - return bcdiv($byte,bcpow($base, $i), $precision).' '.$labels[$i-1].($mibi?'iB':'B'); - return $byte.' Byte'; -} \ No newline at end of file + $bytes = max($bytes, 0); + $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); + $pow = min($pow, count($units) - 1); + + // Uncomment one of the following alternatives + $bytes /= pow(1024, $pow); + // $bytes /= (1 << (10 * $pow)); + + return round($bytes, $precision) . ' ' . $units[$pow]; +} \ No newline at end of file