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

yipeiwu_com6年前PHP代码库

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

相关文章

PHP中使用Imagick读取pdf并生成png缩略图实例

pdf生成png首页缩略图 (服务器需要支持Imagick)  复制代码 代码如下:  /** * PDF2PNG    * @...

从PHP的源码中深入了解stdClass类

在百度百科中,对于stdClass的定义如下:复制代码 代码如下:stdClass在PHP5才开始被流行。而stdClass也是zend的一个保留类。stdClass是PHP的一个基类,...

linux下为php添加iconv模块的方法

./configure --with-mysql=/backup/mysql --with-freetype-dir --with-jpeg-dir --with-png-dir --w...

PHP实现的简单sha1加密功能示例

本文实例讲述了PHP实现的sha1加密功能。分享给大家供大家参考,具体如下: function encryptTokey($data){ $apikey = 'testap...

在WordPress中实现发送http请求的相关函数解析

在 PHP 中发送 Http 请求(GET / POST)有很多的方法,比如 file_get_contents() 函数、fopen() 函数或者 cURL 扩展,但由于服务器的情况不...