css mime类型返回为text/plain而不是text/css [英] css mime type return as text/plain rather than text/css

查看:662
本文介绍了css mime类型返回为text/plain而不是text/css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码从给定文件中获取哑剧类型

I am using this code to get the mime type from a given file

$finfo = new \finfo(FILEINFO_MIME_TYPE);
$mime  = $finfo->buffer(file_get_contents($file));

如果我将其提供给PHP文件,则会得到

If I feed it a PHP file then I get

text/x-php

但是如果我将其喂入CSS文件

but if I feed it a CSS file I get

text/plain

我一直试图解决这个问题,但没有成功,我的Apache中有AddType以允许CSS文件类型.

I have been trying to solve this issue to no avail, I have AddType in my Apache to allow for CSS file types.

有人有建议吗?

推荐答案

每当扩展名时,您都需要告诉Apache将文件作为 text/css 提供. .css .服务器区分样式表和任何其他类型的文本文件的唯一明智的方法是使用文件名.

You need to tell Apache to serve files as text/css whenever their extension is .css. The only sane way for your server to differentiate between a style sheet and any other type of text file, is by its file name.

您可以通过编辑Apache的 MIME类型配置文件来实现,该文件名为 mime.types (根据您的发行版,它位于不同的文件夹中,请尝试/etc/apache2 )进行以下关联:

You can do so by editing Apache's MIME type configuration file, which is named mime.types ( it lives in a different folder depending on your distro, maybe try /etc/apache2 ) to make the following association:

text/css                    css

或者,如果您没有管理员权限,则可以在自己的Web根目录中创建一个 .htaccess 文件.有关这两种方法的更多信息,请此处

Alternately, if you don't have admin access, you can create an .htaccess file in your own web root. More info on both methods here

希望这会有所帮助!

重新阅读我们的问题后,也许我误解了您,而您已经完成了上述步骤?

Upon rereading our question, maybe I misunderstood you, and you have already done the steps above?

如果是这样,您能检查一下您的操作系统读取的模仿类型吗?有适当的命令可以检查模仿类型,在此处:

If so, could you check what your OS is reading the mimetype as? There are appropriiate commands to check mimetype, over here:

此外,添加一个后续检查以查看文件扩展名是否以.css结尾似乎是实用的.有什么理由不能解决这个问题吗?

Also, it seems like it would be pragmatic to add a subsequent check to see if the file extension ends with .css. Is there a reason why this won't work?

这篇关于css mime类型返回为text/plain而不是text/css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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