Examples of php implementing curl upload and download and https login

黄舟
Release: 2023-03-14 12:42:01
Original
1158 people have browsed it

This article mainly introduces the php curl upload, download, and https login implementation code. Friends who need it can refer to

1, curl download


$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);
Copy after login

2. curl upload


$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);
Copy after login

3. curl https login


$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;
Copy after login

The above is the detailed content of Examples of php implementing curl upload and download and https login. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!