将MIME类型转换为文件扩展名PHP [英] Convert MIME type to file Extension PHP

查看:101
本文介绍了将MIME类型转换为文件扩展名PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在PHP文档中浏览了一段时间,但是我找不到将MIME类型扩展名转换为文件类型扩展名的方法.

I've been looking around in the PHP documentation for some time, but I found no way to convert a MIME type extension to a file type extension.

image_type_to_extension

如果文件是图像,则似乎可以使用.在我的特定情况下,mime类型不适用于图像,它们适用于字体类型:"otf,ttf".

Seems to work if the file is an image. In my particular case, the mime types are not for images, they are for font types: 'otf, ttf'.

推荐答案

您可以使用类似的东西:

You could use something like:

function getExtension ($mime_type){

    $extensions = array('image/jpeg' => 'jpeg',
                        'text/xml' => 'xml'
                       );

    // Add as many other Mime Types / File Extensions as you like

    return $extensions[$mime_type];

}

注意:并非每种MIME类型都有固定的文件扩展名.另外,诸如application/octet-stream之类的MIME类型可以引用多个文件扩展名.

Note: not every MIME type has a fixed file extension. Also, MIME types like application/octet-stream can refer to multiple file extensions.

这篇关于将MIME类型转换为文件扩展名PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆