diff options
Diffstat (limited to 'core/SettingsServer.php')
-rw-r--r-- | core/SettingsServer.php | 60 |
1 files changed, 45 insertions, 15 deletions
diff --git a/core/SettingsServer.php b/core/SettingsServer.php index 6846502ac4..3f61670fd6 100644 --- a/core/SettingsServer.php +++ b/core/SettingsServer.php @@ -196,26 +196,12 @@ class SettingsServer * Prior to PHP 5.2.1, or on Windows, --enable-memory-limit is not a * compile-time default, so ini_get('memory_limit') may return false. * - * @see http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes * @return int|bool memory limit in megabytes, or false if there is no limit */ public static function getMemoryLimitValue() { if (($memory = ini_get('memory_limit')) > 0) { - // handle shorthand byte options (case-insensitive) - $shorthandByteOption = substr($memory, -1); - switch ($shorthandByteOption) { - case 'G': - case 'g': - return substr($memory, 0, -1) * 1024; - case 'M': - case 'm': - return substr($memory, 0, -1); - case 'K': - case 'k': - return substr($memory, 0, -1) / 1024; - } - return $memory / 1048576; + return self::getMegaBytesFromShorthandByte($memory); } // no memory limit @@ -223,6 +209,50 @@ class SettingsServer } /** + * Get php post_max_size (in Megabytes) + * + * @return int|bool max upload size in megabytes, or false if there is no limit + */ + public static function getPostMaxUploadSize() + { + if (($maxPostSize = ini_get('post_max_size')) > 0) { + return self::getMegaBytesFromShorthandByte($maxPostSize); + } + + // no max upload size + return false; + } + + /** + * @see http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes + * @param $value + * @return false|float|int + */ + private static function getMegaBytesFromShorthandByte($value) + { + $value = str_replace(' ', '', $value); + + $shorthandByteOption = substr($value, -1); + switch ($shorthandByteOption) { + case 'G': + case 'g': + return substr($value, 0, -1) * 1024; + case 'M': + case 'm': + return substr($value, 0, -1); + case 'K': + case 'k': + return substr($value, 0, -1) / 1024; + } + + if (is_numeric($value)) { + return (int) $value / 1048576; + } + + return false; + } + + /** * Set maximum script execution time. * * @param int $executionTime max execution time in seconds (0 = no limit) |