1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
* 下载远端文件到本地
* @param string $url
* @param string $path
*/
public function downloadFile(string $url, string $path)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
$file = curl_exec($ch);
curl_close($ch);
$resource = fopen($path, 'w');
fwrite($resource, $file);
fclose($resource);
}