从 PHP 中的 mime 类型获取图像类型


Get image type from mime type in PHP

在PHP中,有两个函数,image_type_to_extensionimage_type_to_mime_type,但是,我正在寻找相反的函数。有没有像mime_type_to_image_type这样的东西,所以我可以从 mime 中检索类型(我只有 image/jpeg 或 image/png,并且想最终获得扩展名)?

请注意,我无法使用exif_imagetypegetimagesize,因为托管服务器不允许这样做。出于安全原因,PHP 设置allow_url_fopen已关闭。

谢谢。

您可能可以使用客户端 URL 库 (cURL) 从文件的原始数据中提取此信息。您可以在此相关答案中看到一些示例。