编程语言
首页 > 编程语言> > php 从第三方服务器download图片到本地

php 从第三方服务器download图片到本地

作者:互联网

public function downPdfFromSSQ($contract_id,$url){
   // $url = 'https://openapi.bestsign.info/openapi/v2/storage/contract/download/?sign=OsfjtxLOQ2%2FMplZLGg6hssF
    //%2BDkWtAXDpIREX%2BjNc36SeG8dCPGESGZ00BOGgOz%2FB7GQKO3YPW5IFrfSVFJ5wlBTAW0yz0J0MBKodrDwwTuRmUP1%2BSGOwKgY6jf0oyVASO6%2FYKhMl76G1OKBLTYwwIbGfnvcRnAZBqGmQe0In6KI%3D&developerId=1978813375945114153&rtick=15369196509036&signType=rsa&contractId=153691961701000001';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_HEADER,0);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_TIMEOUT,500);
    if(!file_exists('contracts/'.date('Ym'))){
       @mkdir('contracts/'.date('Ym'),0777,true);
    }
    $outfile = fopen('contracts/'.date('Ym').'/'.$contract_id.'.pdf',"wb+x");  //保存到本地文件的文件名
    curl_setopt($ch,CURLOPT_FILE,$outfile);
    $rtn = curl_exec($ch);
    fclose($outfile);
   if(!curl_errno($ch)){
        echo "RETURN: ".over;
    }else{
        echo 'Curl:error: '.curl_errno($ch);
    }
    curl_close($ch);
}

标签:ch,setopt,contracts,date,download,服务器,curl,php,CURLOPT
来源: https://blog.csdn.net/jameschiang1995/article/details/88430856