diff --git a/src/Symfony/Component/Form/Extension/Validator/Util/ServerParams.php b/src/Symfony/Component/Form/Extension/Validator/Util/ServerParams.php index cac6047ce20ec..b2a4f4b955366 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Util/ServerParams.php +++ b/src/Symfony/Component/Form/Extension/Validator/Util/ServerParams.php @@ -29,18 +29,12 @@ public function getPostMaxSize() return null; } - $max = (int) $iniMax; - - switch (substr($iniMax, -1)) { - case 'G': - $max *= 1024; - case 'M': - $max *= 1024; - case 'K': - $max *= 1024; + if (preg_match('#^(\d+)([bkmgt])#i', $iniMax, $match)) { + $shift = array('b' => 0, 'k' => 10, 'm' => 20, 'g' => 30, 't' => 40); + $iniMax = ($match[1] * (1 << $shift[strtolower($match[2])])); } - return $max; + return (int) $iniMax; } /** diff --git a/src/Symfony/Component/HttpFoundation/File/UploadedFile.php b/src/Symfony/Component/HttpFoundation/File/UploadedFile.php index 63c5386a11b9a..5fffcf2bdb915 100644 --- a/src/Symfony/Component/HttpFoundation/File/UploadedFile.php +++ b/src/Symfony/Component/HttpFoundation/File/UploadedFile.php @@ -235,13 +235,9 @@ public static function getMaxFilesize() return PHP_INT_MAX; } - switch (strtolower(substr($max, -1))) { - case 'g': - $max *= 1024; - case 'm': - $max *= 1024; - case 'k': - $max *= 1024; + if (preg_match('#^(\d+)([bkmgt])#i', $max, $match)) { + $shift = array('b' => 0, 'k' => 10, 'm' => 20, 'g' => 30, 't' => 40); + $max = ($match[1] * (1 << $shift[strtolower($match[2])])); } return (integer) $max;