From 7cdb16979a6c7e75b71dd8c7c5b39b6482041fb8 Mon Sep 17 00:00:00 2001 From: Fabian Henze Date: Thu, 3 Apr 2014 01:17:28 +0200 Subject: Fix setting the max-upload-size for really large values. php can only parse filesize units up to gigabytes, not terabytes or petabytes. --- lib/private/helper.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'lib/private/helper.php') diff --git a/lib/private/helper.php b/lib/private/helper.php index d7ac0b5f4fa..5cd1fbacce7 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -305,6 +305,32 @@ class OC_Helper { return "$bytes PB"; } + /** + * @brief Make a php file size + * @param int $bytes file size in bytes + * @return string a php parseable file size + * + * Makes 2048 to 2k and 2^41 to 2048G + */ + public static function phpFileSize($bytes) { + if ($bytes < 0) { + return "?"; + } + if ($bytes < 1024) { + return $bytes . "B"; + } + $bytes = round($bytes / 1024, 1); + if ($bytes < 1024) { + return $bytes . "K"; + } + $bytes = round($bytes / 1024, 1); + if ($bytes < 1024) { + return $bytes . "M"; + } + $bytes = round($bytes / 1024, 1); + return $bytes . "G"; + } + /** * @brief Make a computer file size * @param string $str file size in human readable format -- cgit v1.2.3