mime_content_type仅针对CSS和JS文件返回文本/纯文本 [英] mime_content_type returning text/plain for css and js files only

查看:386
本文介绍了mime_content_type仅针对CSS和JS文件返回文本/纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用PHP的mime_content_type遇到这个奇怪的问题时,除了CSS和JavaScript文件外,它都能正常工作(PHP的默认mime设置为text/html).

修改mime.types文件似乎没有什么区别(它在httpd.conf上的路径是正确的).

示例

<?php
  echo(mime_content_type('index.html')); // returns text/html
  echo(mime_content_type('default.png')); // returns image/png
  echo(mime_content_type('bootstrap.min.js')); // returns text/plain
  echo(mime_content_type('css/animate.css')); // returns text/plain
  echo(mime_content_type('css/style.css')); // returns text/x-asm
?>

在完全相同的Apache安装上提供的完全相同的文件已正确标记在它们的Content-Type标头上,几乎就像PHP在使用其mime检测机制一样.

我正在使用Wamp 3.0.6 64-bitWindows 10 64-bit build 15063.483 mod_mime and mode_mime_magic上的内置PHP 7.0.10 已启用.

解决方案

PHP文档对此非常明确:

返回文件的MIME内容类型,方法是使用 来自magic.mime文件的信息.

PHP和Apache不使用相同的mime数据库. Apache使用mime.types,但是PHP使用magic.mime(我想不起来它在Unix系统上的位置,/etc/)

不确定如何在Windows上进行编辑,但这是针对Linux的一些提示: 解决方案

The PHP doc is pretty explicit about that:

Returns the MIME content type for a file as determined by using information from the magic.mime file.

PHP and Apache don't use the same mime databases. Apache uses mime.types but PHP uses magic.mime (can't remember where it's located, /etc/ on a Unix system, I think)

No sure how to edit it on Windows but here are some tips for Linux: How to create a custom magic file database

这篇关于mime_content_type仅针对CSS和JS文件返回文本/纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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