【问题标题】:curl_init($url) returns Resource id #7curl_init($url) 返回资源 ID #7
【发布时间】:2012-05-14 02:58:41
【问题描述】:

我一直使用 CURL 功能从 url 获取图像并将其保存到 m 服务器,因为 COPY() 已从我的主机中禁用。

我传递的网址是 $url=http://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/People_from_Switzerland.png/285px-People_from_Switzerland.png

    $headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';              
$headers[] = 'Connection: Keep-Alive';         
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';   
$userAgent = 'php';
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);         
curl_setopt($process, CURLOPT_HEADER, 0);         
curl_setopt($process, CURLOPT_USERAGENT, $useragent);         
curl_setopt($process, CURLOPT_TIMEOUT, 30);         
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);         
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

当我尝试回显 curl_init($url) 输出时出现以下错误

进程资源 id #7
警告:curl_setopt() 期望参数 1 是资源, 中给出 null 警告:curl_errno() 期望参数 1 是资源,在

中给出 null

请帮忙!

【问题讨论】:

    标签: php


    【解决方案1】:

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    $ch是哪里来的,你之前用的是$process,最后一行是从别处抄来的吗?

    未定义的变量将为空。

    【讨论】:

    • 感谢您的回答..你是对的..我在两个不同的函数中出于不同的目的使用了 CURL,在粘贴时我忘记替换这个变量...
    【解决方案2】:

    您忘记在最后一行将$ch 更改为$process

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    

    应该是:

    curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false);
    

    【讨论】:

      【解决方案3】:

      使用 PHP 从您提供的任何 url 下载图像文件并保存。我用它来脸书。

      $headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';  
      $headers[] = 'Connection: Keep-Alive';
      $headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
      
      $userAgent = 'php';
      $process = curl_init('https://sphotos-a.xx.fbcdn.net/xxxx/xxxxxx_n.jpg');
      curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
      curl_setopt($process, CURLOPT_HEADER, 0);     
      curl_setopt($process, CURLOPT_USERAGENT, $useragent);
      curl_setopt($process, CURLOPT_TIMEOUT, 30);
      curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);  
      curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1)
      curl_setopt($process, CURLOPT_BINARYTRANSFER,1);
      curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false);
      $raw=curl_exec($process);
      curl_close ($process);
      $open=fopen('final.jpeg',x);
      $write=fwrite($open,$raw);
      $clo= fclose($open);
      

      【讨论】:

        猜你喜欢
        • 2016-09-30
        • 1970-01-01
        • 1970-01-01
        • 2015-09-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多