function download($url,$id,$cookie,$format){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,TRUE);//是否直接显示内容
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
if($cookie)curl_setopt ($ch, CURLOPT_COOKIE , $cookie );
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$localPath=dirname(__FILE__).'/shutt/'.$id.'.'.$format;
//var_dump($localPath);exit;
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 5242880);//20971520
curl_setopt($ch, CURLOPT_WRITEFUNCTION,function ($ch, $string) use ($localPath) {
$fp = fopen($localPath,'a');
$length = fwrite($fp, $string);
fclose($fp);
return $length;
});
$resp = curl_exec($ch);
$curl_eno = curl_errno($ch);
$curl_err = curl_error($ch);
if($curl_eno){
file_put_contents('./tmp.log', 'step2.0:'.json_encode($resp),FILE_APPEND);
}
curl_close($ch);
return $curl_eno;
}
//断点续传相关参数
//CURLOPT_RESUME_FROM
//CURLOPT_PROGRESSDATA11月62020

发表评论