当前位置:Gxlcms > PHP教程 > php实现curl上传下载https登陆

php实现curl上传下载https登陆

时间:2021-07-01 10:21:17 帮助过:18人阅读

本文主要和大家介绍了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上传文件的简单例子

php使用curl上传文件为什么删掉一句无法执行

以上就是php实现curl上传下载https登陆的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行