从用C文件名获取MIME类型 [英] Get MIME type from filename in C

查看:229
本文介绍了从用C文件名获取MIME类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从使用C.文件名的MIME类型
有没有办法做到这一点,而无需使用包含MIME类型和文件扩展名文本文件(即Apache的文件的mime.types )?

I want to get the MIME type from a filename using C. Is there a way to do this without using a textfile containing MIME types and file extensions (i.e. Apache's file mime.types)?

也许有一个函数来获取使用文件名的MIME类型?我宁可不使用文件扩展名,如果我没有。

Maybe there is a function to get the MIME type using the filename? I rather not use the file extension if I don't have to.

推荐答案

如果有办法做到这一点,阿帕奇不会需要它的mime.types 文件!

If there was a way to do it, Apache wouldn't need its mime.types file!

表在某处。这是不是在由您code解析一个单独的文件,或者很难coded到你的软件。前者是更好的解决方案更清晰...

The table has to be somewhere. It's either in a separate file which is parsed by your code, or it's hard coded into your software. The former is clearer the better solution...

它也可以通过检查该文件的内容,即报头字段,数据结构等,这是由使用的方法文件(1)<在MIME类型的文件的猜测/ code>程序以及通过Apache的 mod_mime_magic模块。在这两种情况下,他们仍然使用一个单独的文本文件来存储查找规则,而不是有任何的细节,程序本身的硬codeD。

It's also possible to guess at the MIME type of a file by examining the content of the file, i.e. header fields, data structures, etc. This is the approach used by the file(1) program and also by Apache's mod_mime_magic. In both cases they still use a separate text file to store the lookup rules rather than have any details hard-coded in the program itself.

这篇关于从用C文件名获取MIME类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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