doujiacai4986 2017-07-19 00:59
浏览 465
已采纳

mime_content_type仅为css和js文件返回text / plain

I'm encountering this weird issue with PHP's mime_content_type, it works fine, except for CSS and JavaScript files, which it returns text/plain for (PHP's default mime is set to do text/html).

Modifying the mime.types file seems to make no difference (its path on httpd.conf is correct).

Examples

<?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
?>

The same exact files served on the same exact Apache installation gets correctly marked on their Content-Type headers, it's almost as if PHP's using its mime detection mechanism.

I'm using Wamp 3.0.6 64-bit and the built-in PHP 7.0.10 on Windows 10 64-bit build 15063.483 mod_mime and mode_mime_magic are enabled.

  • 写回答

1条回答 默认 最新

  • doupi7619 2017-07-19 01:20
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)