我一直
在使用它来从 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 是资源,空值在警告:curl_errno() 期望参数 1 是资源,空值在
请帮忙!
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$ch
从哪里来,你之前用过$process
,最后一行是从其他地方复制的吗?
未定义的变量将为空。
您忘记在最后一行中将$ch
更改为$process
:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
应该是:
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false);
使用 PHP 这会从您提供的任何 url 下载图像文件并保存。我把它用于Facebook。
$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);