【问题标题】:Why is Symfony2 File->getMimeType() returning text/plain not text/css for a CSS file?为什么 Symfony2 File->getMimeType() 为 CSS 文件返回 text/plain 而不是 text/css?
【发布时间】:2013-11-10 07:13:23
【问题描述】:

我需要获取服务器上文件的 MIME 类型。我正在使用 Laravel,但想使用 Symfony HTTPFoundation 中的 File 类(请参阅我的 related question)。

当我在 css 文件上使用 File->GetMimeType() 时,当我期待 text/css 时,会返回 text/plain

$file = new Symfony\Component\HttpFoundation\File\File($path); //pass CSS file
$mime = $file->getMimeType(); //returns text/plain

我做错了什么?

【问题讨论】:

标签: php symfony


【解决方案1】:

查看我对这个问题的回答和简单的解决方案 - https://stackoverflow.com/a/26299430/1331510

然而,我的方法并不完美,但它适用于文件上传:只需从文件名中提取文件扩展名,并使用in:pdf,csv,css,.. 规则检查其是否存在于数组中。

【讨论】:

    猜你喜欢
    • 2012-06-02
    • 2012-09-11
    • 1970-01-01
    • 2016-03-10
    • 2012-05-19
    • 2020-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多