简体   繁体   English

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

[英]Get image type from mime type in PHP

In PHP, there are two functions, image_type_to_extension and image_type_to_mime_type , however, I am looking for the oppsite. 在PHP中,有两个函数image_type_to_extensionimage_type_to_mime_type ,但是,我正在寻找相反的位置。 Is there something like mime_type_to_image_type so I can retrieve the type from the mime (I only have image/jpeg, or image/png, and like to eventually get the extension)? 是否有类似mime_type_to_image_type的东西,所以我可以从mime中检索类型(我只有image / jpeg或image / png,并且希望最终得到扩展名)?

Please note that I cannot use exif_imagetype or getimagesize because the hosting server does not allow it. 请注意,我不能使用exif_imagetypegetimagesize,因为托管服务器不允许使用它。 The php setting allow_url_fopen is turned off for security reasons. 出于安全原因,php设置allow_url_fopen已关闭。

Thanks. 谢谢。

You probably can use the Client URL Library (cURL) to extract this information from the raw data of the file. 您可能可以使用客户端URL库(cURL)从文件的原始数据中提取此信息。 You can see some examples in this related answer . 您可以在此相关答案中看到一些示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM