Add check to ensure finfo_open works in ensure_file function

This commit is contained in:
jrenslin authored and stefan committed 2020-11-08 13:06:05 +01:00
1 parent 306efa3769
commit cb8c786284
1 file changed
+4 -2
+4 -2
View File
@@ -397,13 +397,15 @@ public static function ensure_file(string $filepath, array $accepted_mimetype =
return;
}
$finfo = \finfo_open(FILEINFO_MIME_TYPE);
if (!($finfo = \finfo_open(FILEINFO_MIME_TYPE))) {
throw new Exception("Cannot open finfo context");
}
if (!($mime_type = finfo_file($finfo, $filepath))) {
throw new MDWrongFileType("Cannot get mime type of file: " . basename($filepath));
}
\finfo_close($finfo);
if (!\in_array($mime_type, $accepted_mimetype)) {
if (!\in_array($mime_type, $accepted_mimetype, true)) {
throw new MDWrongFileType("Incorrect mime type of file " . \basename($filepath) . ". Mime type is " . \mime_content_type($filepath) . ", accepted any of ['" . \implode("', '", $accepted_mimetype) . "']");
}