diff options
author | Marc Alexander <admin@m-a-styles.de> | 2015-07-15 16:08:49 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2015-09-09 08:27:59 +0200 |
commit | 167cc58f27da138e138310dafaeff5b53ccedef0 (patch) | |
tree | cf2acd7d05235c2cb5490fc0e2494eea5a927d7e /phpBB/phpbb/files | |
parent | [ticket/13904] Fix minor issues and move local_upload to its own class (diff) | |
download | phpbb-167cc58f27da138e138310dafaeff5b53ccedef0.tar.gz phpbb-167cc58f27da138e138310dafaeff5b53ccedef0.tar.bz2 phpbb-167cc58f27da138e138310dafaeff5b53ccedef0.zip |
[ticket/13904] Add types base class
PHPBB3-13904
Diffstat (limited to 'phpBB/phpbb/files')
-rw-r--r-- | phpBB/phpbb/files/types/base.php | 66 |
1 files changed, 66 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..686ce6f695 --- /dev/null +++ b/phpBB/phpbb/files/types/base.php @@ -0,0 +1,66 @@ +<?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; + +use \phpbb\files\filespec; +use \phpbb\files\upload; +use \phpbb\language\language; + +abstract class base implements type_interface +{ + /** @var language */ + protected $language; + + /** @var upload */ + protected $upload; + + /** + * Check if upload exceeds maximum file size + * + * @param filespec $file Filespec object + * + * @return filespec Returns same filespec instance + */ + public function check_upload_size($file) + { + // PHP Upload filesize exceeded + if ($file->get('filename') == 'none') + { + $max_filesize = @ini_get('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(upload $upload) + { + $this->upload = $upload; + + return $this; + } +} |