From ce4cfd248b4c1c0d044f607804da6b4b312aa239 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Fri, 22 Jun 2012 15:43:57 +0200 Subject: format_bytes(): fix bug if size=0 If $size is 0 log() will return -INF leading to an "undefined offset" error when trying to get the suffix. We fix this by copying the code from fb-client which handles this issue correctly and will also work for sizes above the biggest suffix (won't happen here, but who cares). Signed-off-by: Florian Pritz --- application/helpers/filebin_helper.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'application/helpers/filebin_helper.php') diff --git a/application/helpers/filebin_helper.php b/application/helpers/filebin_helper.php index df4a453f7..f19438a1c 100644 --- a/application/helpers/filebin_helper.php +++ b/application/helpers/filebin_helper.php @@ -1,10 +1,23 @@ = -$boundary) { + break; + } + $size /= 1024.0; + } + + # don't print decimals for bytes + if ($suffix_pos != 0) { + return sprintf("%.2f%s", $size, $suffixes[$suffix_pos]); + } else { + return sprintf("%.0f%s", $size, $suffixes[$suffix_pos]); + } } // Original source: http://www.phpfreaks.com/forums/index.php?topic=198274.msg895468#msg895468 -- cgit v1.2.3-24-g4f1b