如何在PHP中使用file_get_contents获取图像的MIME类型 [英] How to get MIME-type of an image with file_get_contents in PHP
本文介绍了如何在PHP中使用file_get_contents获取图像的MIME类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要获取图像的MIME类型,但是我只有通过file_get_contents
获得的图像的主体.是否可以获取MIME类型?
I need to get the MIME type of an image, but I only have the body of the image which I've got with file_get_contents
. Is there a possibility to get the MIME type?
推荐答案
是的,您可以像这样获得它.
Yes, you can get it like this.
$file_info = new finfo(FILEINFO_MIME_TYPE);
$mime_type = $file_info->buffer(file_get_contents($image_url));
echo $mime_type;
这篇关于如何在PHP中使用file_get_contents获取图像的MIME类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文