diff options
author | Fabian Henze <flyser42@gmx.de> | 2014-04-03 01:17:28 +0200 |
---|---|---|
committer | Fabian Henze <flyser42@gmx.de> | 2014-04-03 01:17:28 +0200 |
commit | 7cdb16979a6c7e75b71dd8c7c5b39b6482041fb8 (patch) | |
tree | 3063e5cd23f3c0d0a4cb46c14c2c79cd26bd6d38 /lib/private/helper.php | |
parent | 6d378515f8e0d1a88089d58c5cbc3a61df06887b (diff) | |
download | nextcloud-server-7cdb16979a6c7e75b71dd8c7c5b39b6482041fb8.tar.gz nextcloud-server-7cdb16979a6c7e75b71dd8c7c5b39b6482041fb8.zip |
Fix setting the max-upload-size for really large values.
php can only parse filesize units up to gigabytes, not terabytes or petabytes.
Diffstat (limited to 'lib/private/helper.php')
-rw-r--r-- | lib/private/helper.php | 26 |
1 files changed, 26 insertions, 0 deletions
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 @@ -306,6 +306,32 @@ class OC_Helper { } /** + * @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 * @return int a file size in bytes |