3

我一直在使用 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

请帮忙!

4

3 回答 3

4

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$ch您之前使用的来自哪里$process,最后一行是从其他地方复制的吗?

未定义的变量将为空。

于 2012-05-14T03:01:34.443 回答
3

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

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

应该:

curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false);
于 2012-05-14T03:00:01.243 回答
0

使用 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);
于 2012-09-04T13:48:42.160 回答