我一直在使用 CURL 功能从 url 获取图像并将其保存到我的服务器,因为我的主机禁用了 COPY()。
我传递的 url 是 $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
,最后一行是从别的地方复制过来的吗?
undefined variable 将为空。
关于php - curl_init($url) 返回资源 ID #7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10577063/