diff options
Diffstat (limited to 'phpBB/phpbb/files/types/base.php')
-rw-r--r-- | phpBB/phpbb/files/types/base.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/phpBB/phpbb/files/types/base.php b/phpBB/phpbb/files/types/base.php new file mode 100644 index 0000000000..3313ad040b --- /dev/null +++ b/phpBB/phpbb/files/types/base.php @@ -0,0 +1,65 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\files\types; + +abstract class base implements type_interface +{ + /** @var \phpbb\language\language */ + protected $language; + + /** @var \bantu\IniGetWrapper\IniGetWrapper */ + protected $php_ini; + + /** @var \phpbb\files\upload */ + protected $upload; + + /** + * Check if upload exceeds maximum file size + * + * @param \phpbb\files\filespec $file Filespec object + * + * @return \phpbb\files\filespec Returns same filespec instance + */ + public function check_upload_size($file) + { + // PHP Upload filesize exceeded + if ($file->get('filename') == 'none') + { + $max_filesize = $this->php_ini->getString('upload_max_filesize'); + $unit = 'MB'; + + if (!empty($max_filesize)) + { + $unit = strtolower(substr($max_filesize, -1, 1)); + $max_filesize = (int) $max_filesize; + + $unit = ($unit == 'k') ? 'KB' : (($unit == 'g') ? 'GB' : 'MB'); + } + + $file->error[] = (empty($max_filesize)) ? $this->language->lang($this->upload->error_prefix . 'PHP_SIZE_NA') : $this->language->lang($this->upload->error_prefix . 'PHP_SIZE_OVERRUN', $max_filesize, $this->language->lang($unit)); + } + + return $file; + } + + /** + * {@inheritdoc} + */ + public function set_upload(\phpbb\files\upload $upload) + { + $this->upload = $upload; + + return $this; + } +} |