Skip to content

Commit

Permalink
[HttpFoundation] Fix getMaxFilesize
Browse files Browse the repository at this point in the history
  • Loading branch information
bennyborn authored and nicolas-grekas committed Jul 30, 2019
1 parent 2113e67 commit 54107ba
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/Symfony/Component/HttpFoundation/File/UploadedFile.php
Expand Up @@ -214,13 +214,26 @@ public function move($directory, $name = null)
*/
public static function getMaxFilesize()
{
$iniMax = strtolower(ini_get('upload_max_filesize'));
$sizePostMax = self::parseFilesize(ini_get('post_max_size'));
$sizeUploadMax = self::parseFilesize(ini_get('upload_max_filesize'));

if ('' === $iniMax) {
return PHP_INT_MAX;
return min([$sizePostMax, $sizeUploadMax]);
}

/**
* Returns the given size from an ini value in bytes.
*
* @return int The given size in bytes
*/
private static function parseFilesize($size)
{
if ('' === $size) {
return 0;

This comment has been minimized.

Copy link
@ausi

ausi Aug 13, 2019

Contributor

Previously PHP_INT_MAX got returned for an empty upload_max_filesize, isn’t this a BC break?

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Aug 13, 2019

Member

looks like so, please provide a PR

This comment has been minimized.

Copy link
@ausi

ausi Aug 13, 2019

Contributor

👍 I will look into it and create a PR

This comment has been minimized.

Copy link
@ausi

ausi Aug 14, 2019

Contributor

Done: #33157

}

$max = ltrim($iniMax, '+');
$size = strtolower($size);

$max = ltrim($size, '+');
if (0 === strpos($max, '0x')) {
$max = \intval($max, 16);
} elseif (0 === strpos($max, '0')) {
Expand All @@ -229,7 +242,7 @@ public static function getMaxFilesize()
$max = (int) $max;
}

switch (substr($iniMax, -1)) {
switch (substr($size, -1)) {
case 't': $max *= 1024;
// no break
case 'g': $max *= 1024;
Expand Down

0 comments on commit 54107ba

Please sign in to comment.