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

 2025-01-15  阅读 222  评论 8  点赞 310

摘要: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, curlop

1、curl下载

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

$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中上传、下载、https登陆的实现方法,需要的朋友可以参考一下。


标签:phpphp教程

评论列表:

  •   weihang666
     发布于 3天前回复该评论
  • 写的很不错,学到了!
显示更多评论

发表评论:

管理员

承接各种程序开发,外贸网站代运营,外贸网站建设等项目
  • 内容2460
  • 积分67666
  • 金币86666

Copyright © 2024 LS'Blog-保定PHP程序员老宋个人博客 Inc. 保留所有权利。 Powered by LS'blog 3.0.3

页面耗时0.0290秒, 内存占用1.94 MB, 访问数据库31次

冀ICP备19034377号