[HttpFoundation] Fix getMaxFilesize
This commit is contained in:
parent
2113e67715
commit
54107bac33
@ -214,13 +214,26 @@ class UploadedFile extends File
|
|||||||
*/
|
*/
|
||||||
public static function getMaxFilesize()
|
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 min([$sizePostMax, $sizeUploadMax]);
|
||||||
return PHP_INT_MAX;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$max = ltrim($iniMax, '+');
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
$size = strtolower($size);
|
||||||
|
|
||||||
|
$max = ltrim($size, '+');
|
||||||
if (0 === strpos($max, '0x')) {
|
if (0 === strpos($max, '0x')) {
|
||||||
$max = \intval($max, 16);
|
$max = \intval($max, 16);
|
||||||
} elseif (0 === strpos($max, '0')) {
|
} elseif (0 === strpos($max, '0')) {
|
||||||
@ -229,7 +242,7 @@ class UploadedFile extends File
|
|||||||
$max = (int) $max;
|
$max = (int) $max;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (substr($iniMax, -1)) {
|
switch (substr($size, -1)) {
|
||||||
case 't': $max *= 1024;
|
case 't': $max *= 1024;
|
||||||
// no break
|
// no break
|
||||||
case 'g': $max *= 1024;
|
case 'g': $max *= 1024;
|
||||||
|
Reference in New Issue
Block a user