php curl上傳、下載、https登陸實(shí)現(xiàn)代碼
更新時(shí)間:2017年07月23日 22:37:20 投稿:mdxy-dxy
這篇文章主要介紹了php curl上傳、下載、https登陸實(shí)現(xiàn)代碼,需要的朋友可以參考下
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); //設(shè)置用戶名和密碼 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); //設(shè)置用戶名和密碼 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;
以上就是關(guān)于php中curl中上傳、下載、https登陸的實(shí)現(xiàn)方法,需要的朋友可以參考一下。
您可能感興趣的文章:
相關(guān)文章
PHP 時(shí)間轉(zhuǎn)換Unix時(shí)間戳代碼
PHP 時(shí)間轉(zhuǎn)換Unix 時(shí)間戳實(shí)現(xiàn)代碼。2010-01-01php實(shí)現(xiàn)數(shù)組縱向轉(zhuǎn)橫向并過(guò)濾重復(fù)值的方法分析
這篇文章主要介紹了php實(shí)現(xiàn)數(shù)組縱向轉(zhuǎn)橫向并過(guò)濾重復(fù)值的方法,結(jié)合具體實(shí)例形式對(duì)比分析了php針對(duì)數(shù)組遍歷、轉(zhuǎn)換與去重相關(guān)操作技巧,需要的朋友可以參考下2017-05-05php和javascript之間變量的傳遞實(shí)現(xiàn)代碼
本文提供一種解決php和javascript之間變量的傳遞的方法,需要的朋友可以參考下2012-12-12php5.4傳引用時(shí)報(bào)錯(cuò)問(wèn)題分析
這篇文章主要介紹了php5.4傳引用時(shí)報(bào)錯(cuò)問(wèn)題,結(jié)合實(shí)例形式分析了php5.4傳引用時(shí)報(bào)錯(cuò)問(wèn)題及解決方法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-01-01PHP彈出提示框并跳轉(zhuǎn)到新頁(yè)面即重定向到新頁(yè)面
本文為大家介紹下使用PHP彈出提示框并跳轉(zhuǎn)到新頁(yè)面,也就是大家所認(rèn)為的重定向,下面的示例大家可以參考下2014-01-01