【问题标题】:Resource interpreted as Image but transferred with MIME type text/html, curl, php资源解释为图像,但使用 MIME 类型 text/html、curl、php 传输
【发布时间】:2014-01-19 19:26:13
【问题描述】:

我遇到了这个我以前从未见过的错误。我正在使用 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;

}

我在我的 HTML 文档中将 MIME 类型设置为 <meta http-equiv="Content-Type" content="image/gif">,但仍然遇到同样的问题。

这是我试图输出图像的形式。

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>";
}

【问题讨论】:

  • 哪个错误你没见过?

标签: php curl mime-types


【解决方案1】:

通过 Google 搜索偶然发现了这个问题。添加我的案例以供参考:

如果你像这样用单引号设置background-image: url('../img/sample.png');,Chrome/Opera 控制台也会显示这个警告。

去掉引号就行了。

【讨论】:

  • +1 - 其他格式错误的background-image 声明也可以看到相同的错误,例如background-image: url();。格式错误的 CSS 可以位于页面上的任何位置,也可以位于链接的样式表中。
  • 感谢您的加入 @cbuckley
【解决方案2】:

Put header('Content-Type: image/gif');在您打印要输出的流之前,在您的 php 块代码中。

【讨论】:

    猜你喜欢
    • 2011-12-24
    • 2014-05-20
    • 2012-12-20
    • 1970-01-01
    • 1970-01-01
    • 2014-10-16
    • 2011-07-18
    • 2012-05-20
    • 2014-07-12
    相关资源
    最近更新 更多