diff --git a/post.php b/post.php index ebb9dc81..1685d447 100644 --- a/post.php +++ b/post.php @@ -1290,25 +1290,31 @@ function handle_post(Context $ctx) try { $ret = Metadata\sniff_image($file['tmp_name']); - if (\in_array($ret[2], Metadata\SUPPORTED_IMAGE_MIME_TYPES)) { - $ext = Metadata\mime_to_ext($ret[2]); - $file['is_an_image'] = !\in_array($ext, $config['allowed_ext_files']); - if ($file['is_an_image']) { - $file['width'] = $ret[0]; - $file['height'] = $ret[1]; - $file['mime'] = $ret[2]; - } - } - $file['is_an_image'] = false; - } catch (\RuntimeException $e) { - $file['is_an_image'] = false; - } + $ext = Metadata\mime_to_ext($ret[2]); - if (!$file['is_an_image']) { - if (!\in_array($file['extension'], $config['allowed_ext_files'])) { - // Should be 'invalid media' really. - error($config['error']['invalidimg']); + // Is it some kind of supported image? + if (\in_array($ret[2], Metadata\SUPPORTED_IMAGE_MIME_TYPES)) { + // Is it allowed? + if (!\in_array($ext, $config['allowed_ext'])) { + error($config['error']['invalidimg']); + } + + $file['is_an_image'] = true; + $file['width'] = $ret[0]; + $file['height'] = $ret[1]; + $file['mime'] = $ret[2]; + } else { + // Is it a supported file? + if (!\in_array($file['extension'], $config['allowed_ext_files'])) { + // Should be 'invalid media' really. + error($config['error']['invalidimg']); + } + $file['is_an_image'] = false; } + } catch (\RuntimeException $e) { + $log = $ctx->get(LogDriver::class); + $log->log(LogDriver::ERROR, "Error while sniffing file '{$e->getMessage()}'"); + error($config['error']['invalidimg']); } // Truncate filename if it is too long