Add check to ensure finfo_open works in ensure_file function

This commit is contained in:
Joshua Ramon Enslin 2020-11-08 13:06:05 +01:00 committed by Stefan Rohde-Enslin
parent 306efa3769
commit cb8c786284
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -397,13 +397,15 @@ final class MD_STD {
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) . "']");
}