]> source.dussan.org Git - nextcloud-server.git/commitdiff
make filesize parsing case insensitive
authorRobin Appelman <icewind1991@gmail.com>
Sun, 11 Dec 2011 22:33:24 +0000 (23:33 +0100)
committerRobin Appelman <icewind1991@gmail.com>
Sun, 11 Dec 2011 22:34:27 +0000 (23:34 +0100)
lib/helper.php

index 5b3e394cafd3821195c5cd3ead775c045978827e..24d436225b7b9dba5d42abd64e2f3eac89d82a01 100644 (file)
@@ -160,24 +160,25 @@ class OC_Helper {
         */
        public static function computerFileSize( $str ){
                $bytes = 0;
+               $str=strtolower($str);
 
                $bytes_array = array(
-                       'B' => 1,
-                       'K' => 1024,
-                       'KB' => 1024,
-                       'MB' => 1024 * 1024,
-                       'M'  => 1024 * 1024,
-                       'GB' => 1024 * 1024 * 1024,
-                       'G'  => 1024 * 1024 * 1024,
-                       'TB' => 1024 * 1024 * 1024 * 1024,
-                       'T'  => 1024 * 1024 * 1024 * 1024,
-                       'PB' => 1024 * 1024 * 1024 * 1024 * 1024,
-                       'P'  => 1024 * 1024 * 1024 * 1024 * 1024,
+                       'b' => 1,
+                       'k' => 1024,
+                       'kb' => 1024,
+                       'mb' => 1024 * 1024,
+                       'm'  => 1024 * 1024,
+                       'gb' => 1024 * 1024 * 1024,
+                       'g'  => 1024 * 1024 * 1024,
+                       'tb' => 1024 * 1024 * 1024 * 1024,
+                       't'  => 1024 * 1024 * 1024 * 1024,
+                       'pb' => 1024 * 1024 * 1024 * 1024 * 1024,
+                       'p'  => 1024 * 1024 * 1024 * 1024 * 1024,
                );
 
                $bytes = floatval($str);
 
-               if (preg_match('#([KMGTP]?B?)$#si', $str, $matches) && !empty($bytes_array[$matches[1]])) {
+               if (preg_match('#([kmgtp]?b?)$#si', $str, $matches) && !empty($bytes_array[$matches[1]])) {
                        $bytes *= $bytes_array[$matches[1]];
                }