php curl上传、下载、https登陆实现代码
2018-09-07 13:55
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,
以上就是关于php中curl中上传、下载、https登陆的实现方法,需要的朋友可以参考一下。
上一篇:创建无限极分类树型结构的简单方法
文章标题:php curl上传、下载、https登陆实现代码
文章链接:http://soscw.com/index.php/essay/13031.html