* curl下载文件
* 根据业务需求
* 通过不同站点去访问路径
* 下载文件
* 但是不同站点需要设置header头
* 这里使用curl方式下载
* 具体看代码:
1 //下载地址 2 $url = 'https://xxxxx.com/download/xxxxx'; 3 //header请求头 [主要用于将请求模拟为浏览器发送请求] 4 $header = array( 5 'xxxx:xxxxxx',//自定义header头 6 'xxxx: xxxxx', 7 //模拟浏览器访问 可以将浏览器中的请求复制出来进行处理 8 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 9 'accept-encoding: gzip, deflate, br', 10 'accept-language: zh-CN,zh;q=0.9', 11 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36', 12 ); 13 //文件存储路径 14 $filename = '/Users/kinsfeng/Desktop/xxx.zip'; 15 $ch = curl_init(); 16 $timeout = 10; 17 curl_setopt($ch, CURLOPT_URL, $url); 18 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 19 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 20 curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 21 $file = curl_exec($ch); 22 curl_close($ch); 23 24 // 保存文件到制定路径 25 file_put_contents($filename, $file); 26 27 unset($file, $url); 28 return true;