php 资源被解释为图像但使用 MIME 类型 text/html 传输 - Magento
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8057030/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Resource interpreted as image but transferred with MIME type text/html - Magento
提问by Jae Kun Choi
I'm getting below error when uploading a new product image for my Magento shop.
为我的 Magento 商店上传新产品图片时出现以下错误。
Resource interpreted as image but transferred with MIME type text/html
Is there a reason why this is happening?
发生这种情况有什么原因吗?
回答by Ian Lewis
This might well occur if your image path is set incorrectly. For example relative to current directory "images/myimage.gif" vs relative to web root "/images/myimage.gif".
如果您的图像路径设置不正确,则很可能会发生这种情况。例如相对于当前目录“images/myimage.gif”与相对于网络根目录“/images/myimage.gif”。
The reference to "text/html" might suggest you have an error being returned by the server.
对“text/html”的引用可能表明您有服务器返回的错误。
回答by stevecomrie
I noticed this problem appearing in my JavaScript Console log. It was a simple case of a CSS file looking for a background image that didn't exist and the server sending a 404 error message in its place.
我注意到这个问题出现在我的 JavaScript 控制台日志中。这是一个简单的 CSS 文件寻找不存在的背景图像并且服务器在其位置发送 404 错误消息的简单案例。
回答by Martin Zeitler
One needs to serve the images with the proper MIME type -
需要使用正确的 MIME 类型提供图像 -
Add this line into the .htaccess file (assuming it's apache2 httpd):
将此行添加到 .htaccess 文件中(假设它是 apache2 httpd):
AddType image/gif .gif
hint: mod_rewrite might require an exclusion for images:
提示:mod_rewrite 可能需要排除图像:
RewriteCond %{REQUEST_URI} !\.(png|gif|jpg)$
RewriteRule ...
... everything else might be 404 indeed.
...其他一切可能确实是 404。
回答by Kim Hogeling
I had the same problem once, because of capitalization.
由于大写,我曾经遇到过同样的问题。
My Colleagues were working on a Mac and added some camel-cased files, but it showed up lowercased in CSS. This works fine on Mac, but I was working on Linux. Mac doesn't distinguish filenames having different cases but Linux does. Most servers out there run on Linux.
我的同事在 Mac 上工作并添加了一些驼峰式文件,但它在 CSS 中显示为小写。这在 Mac 上运行良好,但我在 Linux 上工作。Mac 不区分大小写不同的文件名,但 Linux 区分。大多数服务器都在 Linux 上运行。
example:
例子:
epicimage.jpg !== EpicImage.jpg
Thanks to the Chrome Dev Tools, the problem could be found very easy. Simply clicking on the image url showed me our 404 page. Mystery solved :D
多亏了 Chrome Dev Tools,这个问题很容易被发现。只需单击图片网址即可显示我们的 404 页面。谜团解开了:D
回答by Ralphkay
Please check extensionof your image, whether the program used create the image labels its extension with capital letters or small letters, some servers read them different.
请检查您的图像的扩展名,是否使用创建图像的程序以大写字母或小写字母标记其扩展名,某些服务器读取它们不同。
回答by Hymanie
After a lot of research, I have found the problem is caused by a combination of things resulting in the server not knowing what type of document it is and getting mixed up between encoding types such as UTF-8 (or something like that)
经过大量研究,我发现问题是由多种因素引起的,导致服务器不知道它是什么类型的文档,并且在诸如 UTF-8(或类似的东西)之类的编码类型之间混淆
So, in .htaccess, change the comments round so you have the following, giving a default character set of UTF-8.
因此,在 .htaccess 中,更改注释,以便获得以下内容,并提供 UTF-8 的默认字符集。
############################################
## Prevent character encoding issues from server overrides
## If you still have problems, use the second line instead
#AddDefaultCharset Off
AddDefaultCharset UTF-8
This stopped the correct error shown in google (thank you mr google): "resource interpreted as image but transferred with mime type text/html"
这停止了谷歌中显示的正确错误(谢谢谷歌先生):“资源被解释为图像,但使用 mime 类型 text/html 传输”
And the made the images show up in other browsers (where there was no error shown).
并且使图像显示在其他浏览器中(没有显示错误)。
回答by Strixy
My issue was with this line in the CSS
我的问题是 CSS 中的这一行
background-image: url('');
Which should have been:
应该是:
background-image: none;
回答by emerazea
I checked out basically every similar question on StackOverflow trying to solve a similar issue.
我基本上检查了 StackOverflow 上的所有类似问题,试图解决类似的问题。
After all the attempts at altering my htaccess file and inserting php head arguments, what fixed it for me was ...just changing the capitalization on the picture's name.
在尝试更改我的 htaccess 文件并插入 php head 参数之后,对我来说修复它的是......只是更改图片名称的大小写。
Ugh. (It was working fine in the same browser local-hosted, too... so of course I wouldn't think that was the issue initially.)
啊。(它在本地托管的同一浏览器中也运行良好......所以当然我最初不认为这是问题。)
回答by TechMaze
This happened with me when I was including SVG image via img tag. If you are including SVG image via tag you need to switch to Object tag instead:
<object type="image/svg+xml" data="imageFile.svg">
Test SVG Logo
</object>
当我通过 img 标签包含 SVG 图像时,这发生在我身上。如果您通过标签包含 SVG 图像,则需要切换到 Object 标签:
<object type="image/svg+xml" data="imageFile.svg">
Test SVG Logo
</object>
回答by grayrabbit
For me, this mime type error showed only when testing Safari 4.05 per client requirements, and only in the console. Ultimately this was caused by Safari handling the javascript styling element.style.backgroundImage="url()";
ungracefully. Evidently, Safari was looking for that empty url, so per Strixy and stevecomrie, "none" is the better choice. This is essentially the same issue as noted above as near duplicate of Resource interpreted as other but transferred with MIME type text/javascript?, wherein a <script src="">
was the culprit.
对我来说,这个 mime 类型错误仅在根据客户端要求测试 Safari 4.05 时显示,并且仅在控制台中显示。最终,这是由于 Safarielement.style.backgroundImage="url()";
不雅地处理 javascript 样式造成的。显然,Safari 正在寻找那个空的 url,所以根据 Strixy 和 stevecomrie 的说法,“无”是更好的选择。这本质上与上面提到的问题相同,因为几乎重复的Resource 被解释为其他但使用 MIME 类型 text/javascript 传输?,其中 a<script src="">
是罪魁祸首。