我在 PHP 的 mime_content_type 上遇到了这个奇怪的问题,它工作正常,除了 CSS 和 JavaScript 文件,它返回 text/plain (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
header 上得到正确标记,这几乎就像 PHP 使用其 mime 检测机制一样。
我在 Windows 10 64-bit build 15063.483 mod_mime 上使用
已启用。Wamp 3.0.6 64-bit
和内置 PHP 7.0.10
和mode_mime_magic
最佳答案
PHP 文档对此非常明确:
Returns the MIME content type for a file as determined by using information from the magic.mime file.
PHP 和 Apache 不使用相同的 mime 数据库。 Apache 使用 mime.types
但 PHP 使用 magic.mime
(不记得它的位置,/etc/
在 Unix 系统上,我想想)
不知道如何在 Windows 上编辑它,但这里有一些适用于 Linux 的提示:How to create a custom magic file database
关于php - mime_content_type 仅返回 css 和 js 文件的文本/纯文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45179337/