Convert the upload_max_filesize ini setting to a number of bytes.

@return int The value of the upload_max_filesize in bytes.

@access private
334673
private static function getUploadMaxFileSizeInBytes() {
    $val = trim(ini_get('upload_max_filesize'));
    $unit = strtolower(substr($val, -1));
    switch ($unit) {
      case 'g':
        $val *= 1024;
        // Fall through
      case 'm':
        $val *= 1024;
        // Fall through
      case 'k':
        $val *= 1024;
        break;
    }
    return intval($val);
  }
1163581
protected function getPostMaxSize()
    {
        if (is_numeric($postMaxSize = ini_get('post_max_size'))) {
            return (int) $postMaxSize;
        }

        $metric = strtoupper(substr($postMaxSize, -1));
        $postMaxSize = (int) $postMaxSize;

        switch ($metric) {
            case 'K':
                return $postMaxSize * 1024;
            case 'M':
                return $postMaxSize * 1048576;
            case 'G':
                return $postMaxSize * 1073741824;
            default:
                return $postMaxSize;
        }
    }
1186471
public static function getFileUploadMaxSize($convert_to_bytes = true)
    {
        $max_size = -1;
        $max_size_string = '0B';

        if ($max_size < 0) {
            // Start with post_max_size.
            $max_size_string = ini_get('post_max_size');
            $max_size = self::parseSize($max_size_string);

            // If upload_max_size is less, then reduce. Except if upload_max_size is
            // zero, which indicates no limit.
            $upload_max = self::parseSize(ini_get('upload_max_filesize'));
            if ($upload_max > 0 && $upload_max < $max_size) {
                $max_size = $upload_max;
                $max_size_string = ini_get('upload_max_filesize');
            }
        }

        return $convert_to_bytes ? $max_size : $max_size_string;
    }
465004
private function getPhpUploadMaxFilesize()
	{
		$param = trim(ini_get('upload_max_filesize'));
		$unit = strtolower(substr($param, -1));
		$val = (double) $param;
		switch($unit)
		{
			case 'k':
				$val = \Document::convertFileSize((double) substr($param, 0, - 1), \Document::FILE_SIZE_UNIT_KB, \Document::FILE_SIZE_UNIT_BYTE);
				break;
			case 'm':
				$val = \Document::convertFileSize((double) substr($param, 0, - 1), \Document::FILE_SIZE_UNIT_MB, \Document::FILE_SIZE_UNIT_BYTE);
				break;
			case 'g':
				$val = \Document::convertFileSize((double) substr($param, 0, - 1), \Document::FILE_SIZE_UNIT_GB, \Document::FILE_SIZE_UNIT_BYTE);
				break;
		}
		
		if (!is_double($val))
		{
			throw new \Exception('PHP value for upload_max_filesize could not be determined.');
		}
		return $val;
	}
1174754
public function filesize()
	{
		if ($this->use_include_path) {
			return filesize(stream_resolve_include_path($this->_fhandle));
		} else {
			return filesize($this->_fhandle);
		}
	}
1356589
protected function uploadSingleFile()
    {
        // check if there is error while uploading from error array key.
        if (is_array($this->files[$this->input_file_name]) && array_key_exists('error', $this->files[$this->input_file_name]) && $this->files[$this->input_file_name]['error'] != 0) {
            switch ($this->files[$this->input_file_name]['error']) {
                case 1:
                    $this->setErrorMessage(
                        sprintf(static::__('The uploaded file exceeds the max file size directive. (%s &gt; %s).'), $this->files[$this->input_file_name]['size'], ini_get('upload_max_filesize')),
                        'RDU_' . $this->files[$this->input_file_name]['error'],
                        $this->files[$this->input_file_name]['size'] . ' &gt; ' . ini_get('upload_max_filesize'),
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                case 2:
                    $this->setErrorMessage(
                        static::__('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'),
                        'RDU_' . $this->files[$this->input_file_name]['error'],
                        '',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                case 3:
                    $this->setErrorMessage(
                        static::__('The uploaded file was only partially uploaded.'),
                        'RDU_' . $this->files[$this->input_file_name]['error'],
                        '',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                case 4:
                    $this->setErrorMessage(
                        static::__('You did not upload the file.'),
                        'RDU_' . $this->files[$this->input_file_name]['error'],
                        '',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                case 6:
                    $this->setErrorMessage(
                        static::__('Missing a temporary folder.'),
                        'RDU_' . $this->files[$this->input_file_name]['error'],
                        '',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                case 7:
                    $this->setErrorMessage(
                        static::__('Failed to write file to disk.'),
                        'RDU_' . $this->files[$this->input_file_name]['error'],
                        '',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                case 8:
                    $this->setErrorMessage(
                        static::__('A PHP extension stopped the file upload.'),
                        'RDU_' . $this->files[$this->input_file_name]['error'],
                        '',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
            }
        }

        // validate that there is file upload.
        if (
            empty($this->files[$this->input_file_name]) || 
            (
                is_array($this->files[$this->input_file_name]) && 
                array_key_exists('name', $this->files[$this->input_file_name]) && 
                $this->files[$this->input_file_name]['name'] == null
            ) ||
            (
                is_array($this->files[$this->input_file_name]) && 
                array_key_exists('tmp_name', $this->files[$this->input_file_name]) && 
                $this->files[$this->input_file_name]['tmp_name'] == null
            )
        ) {
            $this->setErrorMessage(
                static::__('You did not upload the file.'),
                'RDU_4',
                '',
                $this->files[$this->input_file_name]['name'],
                $this->files[$this->input_file_name]['size'],
                $this->files[$this->input_file_name]['type']
            );
            return false;
        }

        // validate allowed extension and its mime types.
        $result = $this->validateExtensionAndMimeType();
        if ($result !== true) {
            return false;
        }
        unset($result);

        // validate max file size.
        $result = $this->validateFileSize();
        if ($result !== true) {
            return false;
        }
        unset($result);

        // validate max image dimension.
        $result = $this->validateImageDimension();
        if ($result !== true) {
            return false;
        }
        unset($result);

        // security scan.
        if ($this->security_scan === true) {
            $result = $this->securityScan();
            if ($result !== true) {
                return false;
            }
            unset($result);
        }

        // set new file name (in case that it was not set) and check for reserved file name.
        $tmp_new_file_name = $this->new_file_name;
        $this->setNewFileName();

        // check for safe web file name if this option was set to true.
        if ($this->web_safe_file_name === true) {
            $this->setWebSafeFileName();
        }

        // now, it should all passed validation. add the uploaded file to move uploaded queue in case that it is upload multiple file and has option to stop on error.
        // get the uploaded file extension.
        $file_name_explode = explode('.', $this->files[$this->input_file_name]['name']);
        $file_extension = null;
        if (is_array($file_name_explode)) {
            $file_extension = '.'.$file_name_explode[count($file_name_explode)-1];
        }
        unset($file_name_explode);
        // add to queue.
        $this->move_uploaded_queue = array_merge(
            $this->move_uploaded_queue, 
            array(
                $this->files[$this->input_file_name]['input_file_key'] => array(
                    'name' => $this->files[$this->input_file_name]['name'],
                    'tmp_name' => $this->files[$this->input_file_name]['tmp_name'],
                    'new_name' => $this->new_file_name.$file_extension,
                )
            )
        );
        // restore temp of new file name to ready for next loop of upload multiple.
        $this->new_file_name = $tmp_new_file_name;
        unset($file_extension, $tmp_new_file_name);

        // done.
        return true;
    }
535645
public function getReadableFilesize()
    {
        $size = $this->filesize;
        if ($size < 1) {
            return $size;
        }

        if ($size < 1024) {
            return $size.'b';
        } else {
            $help = $size / 1024;
            if ($help < 1024) {
                return round($help, 1).'kb';
            } else {
                return round(($help / 1024), 1).'mb';
            }
        }
    }
1173142
public function fullByteSize()
    {
        $size = $this->byteSize();
        foreach ($this->members as $variable) {
            $size += $variable->fullByteSize();
        }
        return $size;
    }
640817
public function getSizeFormattedAttribute()
    {
        if ($this->size >= (1000 ** 2))
            return number_format($this->size / (1000 ** 2), 2) . ' MB';
        else if ($this->size >= 1000)
            return number_format($this->size / 1000, 2) . ' KB';
        else if ($this->size > 1)
            return number_format($this->size) . ' bytes';
        else
            return number_format($this->size) . ' byte';
    }
763528
private function getUploadMaxFileSize()
    {
        $postMaxSize = trim(ini_get('post_max_size'));

        if ('' === $postMaxSize) {
            $postMaxSize = PHP_INT_MAX;
        }

        switch (strtolower(substr($postMaxSize, -1))) {
            /** @noinspection PhpMissingBreakStatementInspection */
            case 'g':
                $postMaxSize *= 1024;
            /** @noinspection PhpMissingBreakStatementInspection */
            case 'm':
                $postMaxSize *= 1024;
            case 'k':
                $postMaxSize *= 1024;
        }

        return min(UploadedFile::getMaxFilesize(), (int) $postMaxSize);
    }
1254831
public static function getMaxUploadSize($maxSize = null)
    {
        $maxUpload = (int)(ini_get('upload_max_filesize'));
        $maxPost = (int)(ini_get('post_max_size'));
        $memoryLimit = (int)(ini_get('memory_limit'));
        $min = min($maxUpload, $maxPost, $memoryLimit);
        if ($maxSize) {
            $maxSize = (int)$maxSize;
            return min($maxSize, $min);
        }
        return $min;
    }
795683
public function getSize()
    {
        if ($this->isDirty && $this->bytes) {
            return strlen($this->bytes);
        }
        if ($this->isDirty && $this->filename) {
            return filesize($this->filename);
        }
        if ($this->riakGridFSFile instanceof \RiakGridFSFile) {
            return $this->riakGridFSFile->getSize();
        }
        return 0;
    }
1014605
public function getFileSize()
    {
        $oFile = oxNew(\OxidEsales\Eshop\Application\Model\File::class);
        $oFile->load($this->oxorderfiles__oxfileid->value);

        return $oFile->getSize();
    }
165183
private function maxLength()
	{
		$max = mb_strlen($this->value);
		if (!$ret = $max <= $this->options->max) {
			$this->error(1);
		}

		return $ret;
	}
72477
public function getMaxUploadFileSize()
    {
        static $max_size = -1;

        if ($max_size < 0) {
            // Start with post_max_size.
            $max_size = $this->parseFileSize(ini_get('post_max_size'));

            // If upload_max_size is less, then reduce. Except if upload_max_size is
            // zero, which indicates no limit.
            $upload_max = $this->parseFileSize(ini_get('upload_max_filesize'));

            if ($upload_max > 0 && $upload_max < $max_size) {
                $max_size = $upload_max;
            }
        }
        return $max_size;
    }
939697
private function moveFile()
    {
        $this->setSeveName();

        $files = $this->files;

        if ($this->formats != "" && !in_array($this->fileExt, $this->formats))
        {
            $formats  = implode(',', $this->formats);
            $message  = "Your upload file " . $files["name"] . " is " . $this->fileExt;
            $message .= " format, The system is not allowed to upload, you can only upload " . $formats . " format's file.";

            $this->error($message, 0, true);

            return false;
        }

        if ($files["size"] / 1024 > $this->maxSize)
        {
            $message = "Your upload file " . $files["name"] . "  The file size exceeds of the system limit size " . $this->maxSize . " KB.";
            $this->error($message, 0, true);

            return false;
        }

        // When can't covered
        if (!$this->cover)
        {
            // The same file already exists
            if (file_exists($this->savePath . $this->saveName))
            {
                $this->error($this->saveName . $this->errors['same_file'], 0, true);

                return false;
            }
        }

        if ( !@move_uploaded_file( $files["tmp_name"], iconv("utf-8", "gbk", $this->savePath . $this->saveName) ) )
        {
            switch ($files["error"])
            {
                case '0':
                    $message = "File upload successfully.";
                    break;

                case '1':
                    $message = "The uploaded file exceeds the value of the upload_max_filesize option in php.ini.";
                    break;

                case '2':
                    $message = "The size of the upload file exceeds the value specified by the MAX_FILE_SIZE option in the HTML form.";
                    break;

                case '3':
                    $message = "Only part of the file is uploaded.";
                    break;

                case '4':
                    $message = "No file is uploaded.";
                    break;

                case '6':
                    $message = "Can't find upload temp directory.";
                    break;

                case '7':
                    $message = "Error writing file to hard drive";
                    break;

                case '8':
                    $message = "An extension has stopped the upload of the file.";
                    break;

                case '999':
                default:
                    $message = "Unknown error, please check the file is damaged, whether the oversized and other reasons.";
                    break;
            }

            $this->error($message, 0, true);

            return false;
        }

        @unlink($files["tmp_name"]); // Delete temporary file

        return true;
    }
1330482
private static function parseFileUploadSize($ini_value)
    {
        if (is_numeric($ini_value)) {
            $value = $ini_value;
        } else {
            $size = mb_strtoupper(mb_substr($ini_value, -1));
            $value = (int) mb_substr($ini_value, 0, -1);

            switch ($size) {
                case 'P':
                    $value *= 1024;
                    break;
                case 'T':
                    $value *= 1024;
                    break;
                case 'G':
                    $value *= 1024;
                    break;
                case 'M':
                    $value *= 1024;
                    break;
                case 'K':
                    $value *= 1024;
                    break;
            }
        }

        return $value;
    }