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

Skip to content

Commit 54107ba

Browse files
bennybornnicolas-grekas
authored andcommitted
[HttpFoundation] Fix getMaxFilesize
1 parent 2113e67 commit 54107ba

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,26 @@ public function move($directory, $name = null)
214214
*/
215215
public static function getMaxFilesize()
216216
{
217-
$iniMax = strtolower(ini_get('upload_max_filesize'));
217+
$sizePostMax = self::parseFilesize(ini_get('post_max_size'));
218+
$sizeUploadMax = self::parseFilesize(ini_get('upload_max_filesize'));
218219

219-
if ('' === $iniMax) {
220-
return PHP_INT_MAX;
220+
return min([$sizePostMax, $sizeUploadMax]);
221+
}
222+
223+
/**
224+
* Returns the given size from an ini value in bytes.
225+
*
226+
* @return int The given size in bytes
227+
*/
228+
private static function parseFilesize($size)
229+
{
230+
if ('' === $size) {
231+
return 0;
221232
}
222233

223-
$max = ltrim($iniMax, '+');
234+
$size = strtolower($size);
235+
236+
$max = ltrim($size, '+');
224237
if (0 === strpos($max, '0x')) {
225238
$max = \intval($max, 16);
226239
} elseif (0 === strpos($max, '0')) {
@@ -229,7 +242,7 @@ public static function getMaxFilesize()
229242
$max = (int) $max;
230243
}
231244

232-
switch (substr($iniMax, -1)) {
245+
switch (substr($size, -1)) {
233246
case 't': $max *= 1024;
234247
// no break
235248
case 'g': $max *= 1024;

0 commit comments

Comments
 (0)