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

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.

图片转代码服务由CSDN问答提供 功能建议

我遇到了PHP的mime_content_type这个奇怪的问题,它工作正常,除了CSS和JavaScript文件,它 返回text / plain for(PHP的默认mime设置为text / html)。

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

示例

 &lt;?php 
 echo(mime_content_type('index.html'));  //返回text / html 
 echo(mime_content_type('default.png'));  //返回image / png 
 echo(mime_content_type('bootstrap.min.js'));  //返回text / plain 
 echo(mime_content_type('css / animate.css'));  //返回text / plain 
 echo(mime_content_type('css / style.css'));  //返回text / x-asm 
?&gt; 
   
 
 

在相同的Apache安装上提供的相同确切文件在 Content上正确标记 -Type 标题,几乎就像PHP使用它的mime检测机制一样。

我正在使用 Wamp 3.0.6 64位 Windows 10 64位版本15063.483 mod_mime和mode_mime_magic 上的内置 PHP 7.0.10 已启用。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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

    打赏 评论

相关推荐 更多相似问题