[ticket/13031] Only use mimetype guesser guess if it helps us

If we already have a mimetype and the guesser's guess is the default fallback,
we should keep the already existing mimetype the browser supplied. Otherwise,
platforms that might not support mimetype guessers will cause us to always
have the mimetype set to application/octet-stream on images. This will prevent
users from uploading images.

PHPBB3-13031
This commit is contained in:
Marc Alexander 2014-09-03 23:06:02 +02:00
parent 6777d462ff
commit 7de15bc54c
2 changed files with 8 additions and 3 deletions

View file

@ -232,7 +232,12 @@ class filespec
{
if ($this->mimetype_guesser !== null)
{
$this->mimetype = $this->mimetype_guesser->guess($filename);
$mimetype = $this->mimetype_guesser->guess($filename);
if (empty($this->mimetype) || $mimetype !== 'application/octet-stream')
{
$this->mimetype = $mimetype;
}
}
return $this->mimetype;

View file

@ -107,9 +107,9 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case
$crawler = $this->upload_file('disallowed.jpg', 'image/jpeg');
// Hitting the ATTACHED_IMAGE_NOT_IMAGE error means we passed the
// Hitting the UNABLE_GET_IMAGE_SIZE error means we passed the
// DISALLOWED_CONTENT check
$this->assertContains($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $crawler->text());
$this->assertContainsLang('UNABLE_GET_IMAGE_SIZE', $crawler->text());
}
public function test_too_large()