资源被解释为图像但使用 MIME 类型 text/html、curl、php 传输
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21221497/
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, curl, php
提问by Zy0n
I'm getting this error which i haven't seen before. I'm using cURL to try and get a captcha image from my site, but im getting this error instead of the image i want.
我收到此错误,这是我以前从未见过的。我正在使用 cURL 尝试从我的网站获取验证码图像,但我收到此错误而不是我想要的图像。
if(isset($_GET['captcha'])) {
$curl->open("GET","https://mydomain.com");
$curl->exec();
preg_match('/_mobile_sess=[^;]+/', $curl->getHeaders(), $sess);
$_SESSION['cookie'] = $sess[0];
preg_match('/ame="authenticity_token" type=\"hidden\" value=\"(.+?)\"/i',$curl->responseText, $tkn);
$_SESSION['token'] = $tkn[1];
preg_match('/\/signup\/captcha\/([0-9-a-z]+)\.gif/i', $curl->responseText, $cs);
$_SESSION['captchaUrl'] = $cs[1];
$curl->open("GET", "http://mydomain.com" . $cs[0]);
$curl->cookie = $_SESSION['cookie'];
$curl->exec();
echo $curl->responseText;
die;
}
}
I've set the MIME type as <meta http-equiv="Content-Type" content="image/gif">in my head of my HTML doc but still get the same issue.
我已经将 MIME 类型设置为<meta http-equiv="Content-Type" content="image/gif">在我的 HTML 文档的头部,但仍然遇到相同的问题。
This is the form where i'm trying to output the image.
这是我试图输出图像的形式。
if(empty($_SERVER['QUERY_STRING'])){
echo "<center><form method='POST' action='?go'>
<input type='hidden' name='nameC' value='- SAFAL -' ><br/>
<b>User Name</b><br><input name='login' size='30' id='login' value='safal".rand(111111,9999999)."'><br/>
<b>Password</b><br><input name='senha' id='senha' size='30' value='".rand()."'><br/> <br>
<img src='?captcha'><br/>
<input name='cs' id='cs' placeholder='Put The Capcha' size='20' onclick='if(this.value==\"Digite aqui\") this.value=\"\"'><br><br><br>
<input type='submit' value='Click Here' id='btn'>
</form>";
}
回答by Tyblitz
Stumbled upon this question via Google Search. Adding my case for reference:
通过谷歌搜索偶然发现了这个问题。添加我的案例以供参考:
If you set a background-image: url('../img/sample.png');like this with single quotation marks, the Chrome/ Opera console will also show this warning.
如果background-image: url('../img/sample.png');像这样用单引号设置 a ,Chrome/Opera 控制台也会显示此警告。
Eliminating the quotation marks does the trick.
消除引号可以解决问题。
回答by Frankys
Put header('Content-Type: image/gif'); in your php block code before you are printing a stream to output.
Put header('Content-Type: image/gif'); 在您打印流以输出之前,请在您的 php 块代码中。

