diff options
Diffstat (limited to 'phpBB/includes/functions_upload.php')
| -rw-r--r-- | phpBB/includes/functions_upload.php | 56 | 
1 files changed, 38 insertions, 18 deletions
| diff --git a/phpBB/includes/functions_upload.php b/phpBB/includes/functions_upload.php index 89bc31fa25..dcc9bc4874 100644 --- a/phpBB/includes/functions_upload.php +++ b/phpBB/includes/functions_upload.php @@ -47,6 +47,11 @@ class filespec  	var $upload = '';  	/** +	 * @var \phpbb\filesystem\filesystem_interface +	 */ +	protected $filesystem; + +	/**  	 * The plupload object  	 * @var \phpbb\plupload\plupload  	 */ @@ -62,7 +67,7 @@ class filespec  	* File Class  	* @access private  	*/ -	function filespec($upload_ary, $upload_namespace, \phpbb\mimetype\guesser $mimetype_guesser = null, \phpbb\plupload\plupload $plupload = null) +	function filespec($upload_ary, $upload_namespace, \phpbb\filesystem\filesystem_interface $phpbb_filesystem, \phpbb\mimetype\guesser $mimetype_guesser = null, \phpbb\plupload\plupload $plupload = null)  	{  		if (!isset($upload_ary))  		{ @@ -97,6 +102,7 @@ class filespec  		$this->upload = $upload_namespace;  		$this->plupload = $plupload;  		$this->mimetype_guesser = $mimetype_guesser; +		$this->filesystem = $phpbb_filesystem;  	}  	/** @@ -376,7 +382,14 @@ class filespec  				return false;  			} -			phpbb_chmod($this->destination_file, $chmod); +			try +			{ +				$this->filesystem->phpbb_chmod($this->destination_file, $chmod); +			} +			catch (\phpbb\filesystem\exception\filesystem_exception $e) +			{ +				// Do nothing +			}  		}  		// Try to get real filesize from destination folder @@ -389,28 +402,28 @@ class filespec  		{  			$this->width = $this->height = 0; -			if (($this->image_info = @getimagesize($this->destination_file)) !== false) -			{ -				$this->width = $this->image_info[0]; -				$this->height = $this->image_info[1]; +			// Get imagesize class +			$imagesize = new \fastImageSize\fastImageSize(); -				if (!empty($this->image_info['mime'])) -				{ -					$this->mimetype = $this->image_info['mime']; -				} +			$this->image_info = $imagesize->getImageSize($this->destination_file, $this->mimetype); + +			if ($this->image_info !== false) +			{ +				$this->width = $this->image_info['width']; +				$this->height = $this->image_info['height'];  				// Check image type  				$types = fileupload::image_types(); -				if (!isset($types[$this->image_info[2]]) || !in_array($this->extension, $types[$this->image_info[2]])) +				if (!isset($types[$this->image_info['type']]) || !in_array($this->extension, $types[$this->image_info['type']]))  				{ -					if (!isset($types[$this->image_info[2]])) +					if (!isset($types[$this->image_info['type']]))  					{ -						$this->error[] = sprintf($user->lang['IMAGE_FILETYPE_INVALID'], $this->image_info[2], $this->mimetype); +						$this->error[] = $user->lang('IMAGE_FILETYPE_INVALID', $this->image_info['type'], $this->mimetype);  					}  					else  					{ -						$this->error[] = sprintf($user->lang['IMAGE_FILETYPE_MISMATCH'], $types[$this->image_info[2]][0], $this->extension); +						$this->error[] = $user->lang('IMAGE_FILETYPE_MISMATCH', $types[$this->image_info['type']][0], $this->extension);  					}  				} @@ -502,8 +515,14 @@ class fileupload  	var $upload_timeout = 6;  	/** +	 * @var \phpbb\filesystem\filesystem_interface +	 */ +	protected $filesystem; + +	/**  	* Init file upload class.  	* +	* @param \phpbb\filesystem\filesystem_interface $filesystem  	* @param string $error_prefix Used error messages will get prefixed by this string  	* @param array $allowed_extensions Array of allowed extensions, for example array('jpg', 'jpeg', 'gif', 'png')  	* @param int $max_filesize Maximum filesize @@ -515,13 +534,14 @@ class fileupload  	*										contain any of its values. Defaults to false.  	*  	*/ -	function fileupload($error_prefix = '', $allowed_extensions = false, $max_filesize = false, $min_width = false, $min_height = false, $max_width = false, $max_height = false, $disallowed_content = false) +	function fileupload(\phpbb\filesystem\filesystem_interface $filesystem, $error_prefix = '', $allowed_extensions = false, $max_filesize = false, $min_width = false, $min_height = false, $max_width = false, $max_height = false, $disallowed_content = false)  	{  		$this->set_allowed_extensions($allowed_extensions);  		$this->set_max_filesize($max_filesize);  		$this->set_allowed_dimensions($min_width, $min_height, $max_width, $max_height);  		$this->set_error_prefix($error_prefix);  		$this->set_disallowed_content($disallowed_content); +		$this->filesystem = $filesystem;  	}  	/** @@ -615,7 +635,7 @@ class fileupload  			}  		} -		$file = new filespec($upload, $this, $mimetype_guesser, $plupload); +		$file = new filespec($upload, $this, $this->filesystem, $mimetype_guesser, $plupload);  		if ($file->init_error)  		{ @@ -696,7 +716,7 @@ class fileupload  			$upload['type'] = $filedata['type'];  		} -		$file = new filespec($upload, $this, $mimetype_guesser); +		$file = new filespec($upload, $this, $this->filesystem, $mimetype_guesser);  		if ($file->init_error)  		{ @@ -934,7 +954,7 @@ class fileupload  		$upload_ary['tmp_name'] = $filename; -		$file = new filespec($upload_ary, $this, $mimetype_guesser); +		$file = new filespec($upload_ary, $this, $this->filesystem, $mimetype_guesser);  		$this->common_checks($file);  		return $file; | 
