2012-05-14 57 views
2

有一個CURL功能,我一直用來從URL獲取圖像並將其保存到m服務器,因爲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($網址)輸出

過程中的資源ID#7
警告:curl_setopt()預計參數1是資源,在 警告空給出:curl_errn o()期望參數1是資源,null給出

請幫忙!

回答

4

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

來自哪裏的$ch,你之前使用$process,是從其他地方複製的最後一行?

未定義的變量將爲空。

+0

感謝您的回答..你是正確的..我已經使用CURL在兩個不同的功能用於不同的目的和粘貼時,我忘記了替換這一個變量... – Jay66online

3

你忘了改$ch$process在最後一行:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

應該是:

curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false); 
0

使用PHP從您提供的任何網址下載圖片文件並保存。我用它的臉譜。

$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);