php curl上传、下载、https登陆实现代码

前端之家收集整理的这篇文章主要介绍了php curl上传、下载、https登陆实现代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、curl下载

PHP;"> $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上传

PHP;"> $ch = curl_init(); $localfile = "ftp01.PHP"; $fp = fopen($localfile,'r'); curl_setopt($ch,"ftp://127.0.0.1/ftp01_upload.PHP"); curl_setopt($ch,"yuejide:123456");

curl_setopt($ch,CURLOPT_UPLOAD,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登录

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

以上就是关于PHP中curl中上传、下载、https登陆的实现方法,需要的朋友可以参考一下。

原文链接:https://www.f2er.com/php/17103.html

猜你在找的PHP相关文章