暮色呼如
$dst_file = fopen(sys_get_temp_dir() . '/' . uniqid($time) . '.txt','w');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 3600);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 20971520);
$flag=0;
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($ch ,$str) use (&$flag,$dst_file){
$len = strlen($str);
file_put_contents($dst_file,$str,FILE_APPEND);
return $len;
});
$output = curl_exec($ch);
fclose($dst_file);
curl_close($ch);
curl下载文件可以用上面的方法。