diff options
author | Marc Alexander <admin@m-a-styles.de> | 2013-10-24 12:05:00 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2013-10-24 12:05:00 +0200 |
commit | bc7ff47537bae4f6db9de781cf8ba3487e28a30b (patch) | |
tree | 8cb137952d6b138c19e63f435c462cd93e091e5b | |
parent | 24099583a32608c2350bdb10d018d6c8a0551e6c (diff) | |
download | forums-bc7ff47537bae4f6db9de781cf8ba3487e28a30b.tar forums-bc7ff47537bae4f6db9de781cf8ba3487e28a30b.tar.gz forums-bc7ff47537bae4f6db9de781cf8ba3487e28a30b.tar.bz2 forums-bc7ff47537bae4f6db9de781cf8ba3487e28a30b.tar.xz forums-bc7ff47537bae4f6db9de781cf8ba3487e28a30b.zip |
[ticket/11912] Supply filename to content_guesser for guessing on windows
The filename of the files sent to the guesser by plupload do not contain
the file extension. Therefore, it's impossible to guess the mimetype if
only the content_guesser is available and the function mime_content_type()
doesn't exist. By supplying the filename we can circumvent this issue.
PHPBB3-11912
-rw-r--r-- | phpBB/phpbb/mimetype/content_guesser.php | 16 | ||||
-rw-r--r-- | phpBB/phpbb/mimetype/guesser.php | 4 | ||||
-rw-r--r-- | phpBB/phpbb/plupload/plupload.php | 2 | ||||
-rw-r--r-- | tests/mimetype/guesser_test.php | 3 |
4 files changed, 17 insertions, 8 deletions
diff --git a/phpBB/phpbb/mimetype/content_guesser.php b/phpBB/phpbb/mimetype/content_guesser.php index 6bdd410af4..6326bf73fa 100644 --- a/phpBB/phpbb/mimetype/content_guesser.php +++ b/phpBB/phpbb/mimetype/content_guesser.php @@ -492,7 +492,7 @@ class content_guesser * * @return string Guess for mimetype of file */ - public function guess($file) + public function guess($file, $file_name = '') { $mimetype = null; if (function_exists('mime_content_type')) @@ -501,14 +501,22 @@ class content_guesser } else { - $mimetype = $this->map_extension_to_type($file); + $file_name = (empty($file_name)) ? $file : $file_name; + $mimetype = $this->map_extension_to_type($file_name); } return $mimetype; } - protected function map_extension_to_type($file) + /** + * Map extension of supplied file_name to mime type + * + * @param string $file_name Path to file or filename + * + * @return string|null Mimetype if known or null if not + */ + protected function map_extension_to_type($file_name) { - $extension = pathinfo($file, PATHINFO_EXTENSION); + $extension = pathinfo($file_name, PATHINFO_EXTENSION); if (isset($this->extension_map[$extension])) { diff --git a/phpBB/phpbb/mimetype/guesser.php b/phpBB/phpbb/mimetype/guesser.php index 5ae094cd63..231b75f604 100644 --- a/phpBB/phpbb/mimetype/guesser.php +++ b/phpBB/phpbb/mimetype/guesser.php @@ -77,7 +77,7 @@ class guesser * * @return string Guess for mimetype of file */ - public function guess($file) + public function guess($file, $file_name = '') { if (!is_file($file)) { @@ -91,7 +91,7 @@ class guesser foreach ($this->guessers as $guesser) { - $mimetype = $guesser->guess($file); + $mimetype = $guesser->guess($file, $file_name); // Try to guess something that is not the fallback application/octet-stream if ($mimetype !== null && $mimetype !== 'application/octet-stream') diff --git a/phpBB/phpbb/plupload/plupload.php b/phpBB/phpbb/plupload/plupload.php index 29a4aff39b..dedc3cbcd4 100644 --- a/phpBB/phpbb/plupload/plupload.php +++ b/phpBB/phpbb/plupload/plupload.php @@ -135,7 +135,7 @@ class plupload 'tmp_name' => $file_path, 'name' => $this->request->variable('real_filename', ''), 'size' => filesize($file_path), - 'type' => $this->mimetype_guesser->guess($file_path), + 'type' => $this->mimetype_guesser->guess($file_path, $file_name), ); } else diff --git a/tests/mimetype/guesser_test.php b/tests/mimetype/guesser_test.php index 6484606210..9d4d965d63 100644 --- a/tests/mimetype/guesser_test.php +++ b/tests/mimetype/guesser_test.php @@ -119,8 +119,9 @@ class guesser_test extends \phpbb_test_case public function test_content_guesser($expected, $overload = false) { self::$function_exists = ($overload) ? false : true; - $guesser = new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\content_guesser($this->phpbb_root_path, new \phpbb\php\ini))); + $guesser = new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\content_guesser)); $this->assertEquals($expected[0], $guesser->guess($this->jpg_file)); + $this->assertEquals($expected[1], $guesser->guess($this->jpg_file, $this->jpg_file . '.jpg')); @copy($this->jpg_file, $this->jpg_file . '.jpg'); $this->assertEquals($expected[1], $guesser->guess($this->jpg_file . '.jpg')); @unlink($this->jpg_file . '.jpg'); |