Php不返回正确的MIME类型 [英] Php doesn't return the correct mime type

查看:224
本文介绍了Php不返回正确的MIME类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

finfo 函数返回疯狂的mime类型。看下面的代码,发生了什么?

The finfo function is returning crazy mime types. Look the following code, what is going on?

<?php
    $files = array ("css.css", "index.html", "js.js", "png.png");

    $info = finfo_open (FILEINFO_MIME_TYPE);

    for ($i = 0; $i < count ($files); $i ++) {
        $type = finfo_file ($info, $files[$i]);

        $files[$i] = $type;
    }

    finfo_close ($info);

    echo $files[0]; // text/x-c -> WHAT ?!
    echo $files[1]; // text/html -> Ok !
    echo $files[2]; // text/x-c++ -> WHAT ?!
    echo $files[3]; // image/png -> Ok !
?>

感谢

推荐答案

我不是非常熟悉fileinfo的工作,但我认为这是正常的。文本文件(这就是CSS和JS)没有提供什么内容的明确指针。它们没有标题字节,没有定义的结构。因此,所有糟糕的 fileinfo 可以做的是猜测 - 结果不佳,你可以看到。

I'm not intimately familiar with the workings of fileinfo, but I think this is normal. Text files (and that's what CSS and JS are) provide no clear pointers as to what content it has. They have no header bytes, no defined structure. So all poor fileinfo can do is guess - with poor results, as you can see.

我想要成功验证.js和.css文件的内容,您必须依赖扩展程序,或者实际上解析用正确的,适当的解析器。

I think to successfully verify the contents of .js and .css files, you have to either rely on the extension, or actually parse them with the correct, appropriate parser.

这篇关于Php不返回正确的MIME类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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