From 3674c22b3162b8ffba8474a8e4314646ab099ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Mon, 18 Mar 2013 17:08:21 +0100 Subject: [PATCH] changed bytes conversion method --- .../Form/Extension/Validator/Util/ServerParams.php | 14 ++++---------- .../Component/HttpFoundation/File/UploadedFile.php | 10 +++------- 2 files changed, 7 insertions(+), 17 deletions(-) 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;