Using PHP, I'd like to check if a uploaded image is in jpg, gif, png, or svg format. I found exif_imagetype function could check the file format, but it does not support svg format. Is there any way to detect svg format in PHP?
To extend Victors answer, you can use mime_content_type('/path/to/file');
(see php.net manual for the function) and check if the return string is equal to image/svg+xml
. Something like:
public function isSvg($filePath = '/path/to/file')
{
return 'image/svg+xml' === mime_content_type($filePath);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With