首頁  >  文章  >  後端開發  >  php 實現curl上傳、下載、https登陸

php 實現curl上傳、下載、https登陸

墨辰丷
墨辰丷原創
2018-05-19 09:55:201779瀏覽

這篇文章主要介紹了php curl上傳、下載、https登陸實現代碼,需要的朋友可以參考下

#1、curl下載

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "ftp://127.0.0.1/downtest.txt"); 
curl_setopt($ch, CURLOPT_HEADER,0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch, CURLOPT_TIMEOUT,300); 
//设置用户名和密码 
curl_setopt($ch, CURLOPT_USERPWD,"yuejide:123456"); 
$outfile = fopen("test.txt","wb"); 
curl_setopt($ch,CURL_FILE,$outfile); 
$rtn = curl_exec($ch); 
fclose($outfile); 
if(!curl_errno($ch)){ 
echo $rtn; 
}else{ 
echo 'curl error'.curl_errno($ch); 
} 
curl_close($ch);

2、curl上傳

$ch = curl_init(); 
$localfile = "ftp01.php"; 
$fp = fopen($localfile,'r'); 
curl_setopt($ch, CURLOPT_URL, "ftp://127.0.0.1/ftp01_upload.php"); 
curl_setopt($ch, CURLOPT_HEADER,0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch, CURLOPT_TIMEOUT,300); 
//设置用户名和密码 
curl_setopt($ch, CURLOPT_USERPWD,"yuejide:123456"); 

curl_setopt($ch, CURLOPT_UPLOAD,1); 
curl_setopt($ch, CURLOPT_INFILE,$fp); 
curl_setopt($ch, CURLOPT_INFILESIZE,filesize($localfile)); 
$rtn = curl_exec($ch); 
fclose($fp); 
if(!curl_errno($ch)){ 
echo "upload successfully"; 
}else{ 
echo 'curl_error'.curl_error($ch); 
} 
curl_close($ch);

#3、curl https登入

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "https://www.baidu.com"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
date_default_timezone_set('PRC'); 
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0); 
$output = curl_exec($ch); 
curl_close($ch); 
echo $output;

#相關推薦:

PHP 傳輸會話curl函數

#PHP基於CURL發送JSON格式字串步驟詳解

Curl下載檔案顯示即時進度列(附程式碼)

以上是php 實現curl上傳、下載、https登陸的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn