mime_content_type 仅针对 css 和 js 文件返回 text/plain
mime_content_type returning text/plain for css and js files only
我在 PHP 的 mime_content_type 中遇到了这个奇怪的问题,它工作正常,除了 CSS 和 JavaScript 文件,它 returns text/plain for (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
headers 上得到了正确标记,这几乎就像 PHP 使用其 mime 检测机制一样。
我正在使用 Wamp 3.0.6 64-bit
和 Windows 10 64-bit build 15063.483 mod_mime and mode_mime_magic
上的 built-in PHP 7.0.10
已启用。
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
(不记得它的位置,我认为在 Unix 系统上是 /etc/
)
不知道如何在 Windows 上编辑它,但这里有一些 Linux 的提示:How to create a custom magic file database
我在 PHP 的 mime_content_type 中遇到了这个奇怪的问题,它工作正常,除了 CSS 和 JavaScript 文件,它 returns text/plain for (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
headers 上得到了正确标记,这几乎就像 PHP 使用其 mime 检测机制一样。
我正在使用 Wamp 3.0.6 64-bit
和 Windows 10 64-bit build 15063.483 mod_mime and mode_mime_magic
上的 built-in PHP 7.0.10
已启用。
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
(不记得它的位置,我认为在 Unix 系统上是 /etc/
)
不知道如何在 Windows 上编辑它,但这里有一些 Linux 的提示:How to create a custom magic file database