Fix and add SVG support

This commit is contained in:
Fyutins 2023-09-26 18:51:12 +02:00
parent d2184eef0a
commit 431eafb2b6

View file

@ -123,14 +123,16 @@ function isImage(string $file, string $extension): bool
return false; return false;
} }
$tempFileName = tempnam("/tmp", "image-check-"); $tempFileName = @tempnam("/tmp", "image-check-");
$handle = fopen($tempFileName, "w"); $handle = fopen($tempFileName, "w");
fwrite($handle, $file); fwrite($handle, $file);
$size = @getimagesize($tempFileName);
fclose($handle); fclose($handle);
if ($extension == 'svg') {
return 'image/svg+xml' === mime_content_type($tempFileName);
}
$size = @getimagesize($tempFileName);
return is_array($size) && str_starts_with($size['mime'], 'image'); return is_array($size) && str_starts_with($size['mime'], 'image');
} }