Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3674c22

Browse files
committed
changed bytes conversion method
1 parent d832dbf commit 3674c22

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

src/Symfony/Component/Form/Extension/Validator/Util/ServerParams.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,12 @@ public function getPostMaxSize()
2929
return null;
3030
}
3131

32-
$max = (int) $iniMax;
33-
34-
switch (substr($iniMax, -1)) {
35-
case 'G':
36-
$max *= 1024;
37-
case 'M':
38-
$max *= 1024;
39-
case 'K':
40-
$max *= 1024;
32+
if (preg_match('#^(\d+)([bkmgt])#i', $iniMax, $match)) {
33+
$shift = array('b' => 0, 'k' => 10, 'm' => 20, 'g' => 30, 't' => 40);
34+
$iniMax = ($match[1] * (1 << $shift[strtolower($match[2])]));
4135
}
4236

43-
return $max;
37+
return (int) $iniMax;
4438
}
4539

4640
/**

src/Symfony/Component/HttpFoundation/File/UploadedFile.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,9 @@ public static function getMaxFilesize()
235235
return PHP_INT_MAX;
236236
}
237237

238-
switch (strtolower(substr($max, -1))) {
239-
case 'g':
240-
$max *= 1024;
241-
case 'm':
242-
$max *= 1024;
243-
case 'k':
244-
$max *= 1024;
238+
if (preg_match('#^(\d+)([bkmgt])#i', $max, $match)) {
239+
$shift = array('b' => 0, 'k' => 10, 'm' => 20, 'g' => 30, 't' => 40);
240+
$max = ($match[1] * (1 << $shift[strtolower($match[2])]));
245241
}
246242

247243
return (integer) $max;

0 commit comments

Comments
 (0)