diff options
author | Marc Alexander <admin@m-a-styles.de> | 2014-01-09 23:50:40 +0100 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2014-06-23 21:37:47 +0200 |
commit | 9bc6e641bfbe53c3920662ee8e24a723ac34e6a1 (patch) | |
tree | e988faa6aa56d42c40ac4121e90c01a9b1d55a8b /phpBB/includes/functions_upload.php | |
parent | 83326718132811d8b57ac8612ff50887ec0fa101 (diff) | |
download | forums-9bc6e641bfbe53c3920662ee8e24a723ac34e6a1.tar forums-9bc6e641bfbe53c3920662ee8e24a723ac34e6a1.tar.gz forums-9bc6e641bfbe53c3920662ee8e24a723ac34e6a1.tar.bz2 forums-9bc6e641bfbe53c3920662ee8e24a723ac34e6a1.tar.xz forums-9bc6e641bfbe53c3920662ee8e24a723ac34e6a1.zip |
[ticket/11148] Add mimetype guesser to filespec and fileupload class
The mimetype guesser will be used to get the mimetype of uploaded files.
Until now, this was only used for files uploaded with plupload. If a file
doesn't have a mimetype supplied, we will now try to get the correct mimetype.
PHPBB3-11148
Diffstat (limited to 'phpBB/includes/functions_upload.php')
-rw-r--r-- | phpBB/includes/functions_upload.php | 58 |
1 files changed, 26 insertions, 32 deletions
diff --git a/phpBB/includes/functions_upload.php b/phpBB/includes/functions_upload.php index c640865212..fb153a9e0c 100644 --- a/phpBB/includes/functions_upload.php +++ b/phpBB/includes/functions_upload.php @@ -53,10 +53,16 @@ class filespec protected $plupload; /** + * phpBB Mimetype guesser + * @var \phpbb\mimetype\guesser + */ + protected $mimetype_guesser; + + /** * File Class * @access private */ - function filespec($upload_ary, $upload_namespace, \phpbb\plupload\plupload $plupload = null) + function filespec($upload_ary, $upload_namespace, \phpbb\mimetype\guesser $mimetype_guesser = null, \phpbb\plupload\plupload $plupload = null) { if (!isset($upload_ary)) { @@ -90,6 +96,7 @@ class filespec $this->local = (isset($upload_ary['local_mode'])) ? true : false; $this->upload = $upload_namespace; $this->plupload = $plupload; + $this->mimetype_guesser = $mimetype_guesser; } /** @@ -215,25 +222,22 @@ class filespec } /** - * Get mimetype. Utilize mime_content_type if the function exist. - * Not used at the moment... + * Get mimetype + * */ function get_mimetype($filename) { - $mimetype = ''; - - if (function_exists('mime_content_type')) + if ($this->mimetype_guesser !== null) { - $mimetype = mime_content_type($filename); - } + $mimetype = $this->mimetype_guesser->guess($filename); - // Some browsers choke on a mimetype of application/octet-stream - if (!$mimetype || $mimetype == 'application/octet-stream') - { - $mimetype = 'application/octetstream'; + if ($mimetype !== 'application/octet-stream') + { + $this->mimetype = $mimetype; + } } - return $mimetype; + return $this->mimetype; } /** @@ -372,6 +376,9 @@ class filespec // Try to get real filesize from destination folder $this->filesize = (@filesize($this->destination_file)) ? @filesize($this->destination_file) : $this->filesize; + // Get mimetype of supplied file + $this->mimetype = $this->get_mimetype($this->destination_file); + if ($this->is_image() && !$skip_image_check) { $this->width = $this->height = 0; @@ -580,7 +587,7 @@ class fileupload * @return object $file Object "filespec" is returned, all further operations can be done with this object * @access public */ - function form_upload($form_name, \phpbb\plupload\plupload $plupload = null) + function form_upload($form_name, \phpbb\mimetype\guesser $mimetype_guesser = null, \phpbb\plupload\plupload $plupload = null) { global $user, $request; @@ -596,7 +603,7 @@ class fileupload } } - $file = new filespec($upload, $this, $plupload); + $file = new filespec($upload, $this, $mimetype_guesser, $plupload); if ($file->init_error) { @@ -656,7 +663,7 @@ class fileupload /** * Move file from another location to phpBB */ - function local_upload($source_file, $filedata = false) + function local_upload($source_file, $filedata = false, \phpbb\mimetype\guesser $mimetype_guesser = null) { global $user, $request; @@ -670,19 +677,6 @@ class fileupload $upload['name'] = utf8_basename($source_file); $upload['size'] = 0; $mimetype = ''; - - if (function_exists('mime_content_type')) - { - $mimetype = mime_content_type($source_file); - } - - // Some browsers choke on a mimetype of application/octet-stream - if (!$mimetype || $mimetype == 'application/octet-stream') - { - $mimetype = 'application/octetstream'; - } - - $upload['type'] = $mimetype; } else { @@ -691,7 +685,7 @@ class fileupload $upload['type'] = $filedata['type']; } - $file = new filespec($upload, $this); + $file = new filespec($upload, $this, $mimetype_guesser); if ($file->init_error) { @@ -749,7 +743,7 @@ class fileupload * @return object $file Object "filespec" is returned, all further operations can be done with this object * @access public */ - function remote_upload($upload_url) + function remote_upload($upload_url, \phpbb\mimetype\guesser $mimetype_guesser = null) { global $user, $phpbb_root_path; @@ -904,7 +898,7 @@ class fileupload $upload_ary['tmp_name'] = $filename; - $file = new filespec($upload_ary, $this); + $file = new filespec($upload_ary, $this, $mimetype_guesser); $this->common_checks($file); return $file; |