4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form\Extension\Validator\Util
;
15 * @author Bernhard Schussek <bschussek@gmail.com>
20 * Returns maximum post size in bytes.
22 * @return null|integer The maximum post size in bytes
24 public function getPostMaxSize()
26 $iniMax = $this->getNormalizedIniPostMaxSize();
32 if (preg_match('#^\+?(0X?)?(.*?)([KMG]?)$#', $iniMax, $match)) {
33 $shifts = array('' => 0, 'K' => 10, 'M' => 20, 'G' => 30);
34 $bases = array('' => 10, '0' => 8, '0X' => 16);
36 return intval($match[2], $bases[$match[1]]) << $shifts[$match[3]];
43 * Returns the normalized "post_max_size" ini setting.
47 public function getNormalizedIniPostMaxSize()
49 return strtoupper(trim(ini_get('post_max_size')));
53 * Returns the content length of the request.
55 * @return mixed The request content length.
57 public function getContentLength()
59 return isset($_SERVER['CONTENT_LENGTH'])
60 ? (int) $_SERVER['CONTENT_LENGTH']