“资源解释为图像但使用MIME类型text / html传输”这一非常奇怪的问题

时间:2012-05-29 22:36:44

标签: php image upload load mime

我查了很多关于这个问题的帖子,但没有与我的相符。

我正在测试我的项目,我收到此警告或错误(我不确切知道)

Resource interpreted as Image but transferred with MIME type text/html

加载了同一文件夹中的某些图像,但有些不是。

THIS IS THE SITE - 上传网站

10分钟前,这个问题不是,但现在它突然出现了。

即使在我测试此网站数百次的计算机上也是如此。

我确信这不是一个.htaccess问题。

我该怎么办?

谢谢!

2 个答案:

答案 0 :(得分:1)

您正在构建图像并通过count.php向下发送,但您没有更改标题以反映相应的mime类型。您需要更改标题以反映响应本身的内容类型。

示例:

我想通过PHP脚本发送PNG文件,因此我需要设置内容类型以反映这一点:

$im = imagecreatefrompng("test.png");
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);

答案 1 :(得分:1)

我遇到了同样的问题,但在谷歌进行密集搜索之后,问题就解决了。这个提示可能会帮助一些有同样问题的人。 我已经摆弄了Apache httpd.conf文件。请转到文件的以下部分:

</IfModule> mime_module>
#
# TypesConfig points to the file containing the list of mappings from
# filename extension to MIME-type.
#
TypesConfig conf/mime.types

#
# AddType allows you to add to or override the MIME configuration
# file specified in TypesConfig for specific file types.
#
#AddType application/x-gzip .tgz
#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
#
#AddEncoding x-compress .Z
#AddEncoding x-gzip .gz .tgz
#
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz

#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
AddHandler cgi-script .cgi

# For type maps (negotiated resources):
#AddHandler type-map var

#
# Filters allow you to process content before it is sent to the client.
#
# To parse .shtml files for server-side includes (SSI):
# (You will also need to add "Includes" to the "Options" directive.)
#
#AddType text/html .shtml
#AddOutputFilter INCLUDES .shtml
AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml



</IfModule>

确保添加以下AddTypes包含在上面的模块WITHOUT POUND(#)KEY中。当您在模块中添加它们时,请不要在任何以下AddTypes前面使用#key,这样Apache服务器将读取它们:

AddType image/gif .gif

AddType image/jpeg .jpeg .jpg

AddType image/png .png