4

I'm not a stranger to mime types but this is strange. Normally, a text file would have been considered to be of text/plain mime but now, after implementing fileinfo, this type of file is now considered to be "text/x-pascal". I'm a little concerned because I need to be sure that I get the correct mime types set before allowing users to upload with it.

Is there a cheat sheet that will give me all of the "common" mimes as they are interpreted by fileinfo?


Sinan provided a link that lists all of the more common mimes. If you look at this list, you will see that a .txt file is of text/plain mime but in my case, a plain-jane text file is interpreted as text/pascal.

4

4 回答 4

4

fileinfo是“最佳猜测”。它只分析文件的一部分以试图找出文件的类型,因此很容易被愚弄。也许您的文件以 Pascal 注释或关键字开头,例如Projector Unit

于 2010-02-27T02:29:10.237 回答
3

Fileinfo is not using the extension of the file to determine which mime-type it is, but (quoting) :

The functions in this module try to guess the content type and encoding of a file by looking for certain magic byte sequences at specific positions within the file.

The idea being that the name à of the file, and its extension, are provided by the users (especially in a case such as yours, where the files are being uploaded by users), and, as such, are less "sure" than the content of the file itself.


Maybe a solution could be to not check on the whole mime-type returned by fileinfo, but to only use the first part of it -- at least in some cases ?

For instance, maybe you could accept all mimetype that are in the text/* and image/* families, and refuse all those look like application/*, except for application/pdf ?
(Just an example -- but you see the point)

于 2010-02-27T09:16:31.573 回答
3

我发现,至少从 5.03 版开始,“ file ”命令在某些情况下可能会将纯文本文件错误地识别为 Pascal 源文件,这仅仅是因为它包含“program”或​​“record”一词。至少在检查源代码 (src/names.h) 后看起来是这样。我相信 php fileinfo 命令使用相同的“魔术”引擎,所以我怀疑这是问题的原因。如果/当我在文件邮件列表中被接受时,我会通知维护者这个问题。

[更新] 我问了这个问题,但几乎没有得到回应。对这个问题进行了更彻底的调查后,发现识别文本格式通常非常困难。如果您从文件中返回“text/*”MIME 类型,您可能需要考虑忽略结果并假设资源只是“text/plain”,除非误报(可能是 text/html)会给您带来困难。

于 2010-05-10T16:40:19.290 回答
2

There is a chart that shows a list of common MIME types and their corresponding extensions. Here

于 2010-02-27T01:40:23.913 回答