好的,得到了解决方案。分享我的答案。
$getFile = 'http://url to file/file.csv';
$getParams = array ();
$path = '/var/save/to/local/path/file_name.csv';
$fp = fopen($path, 'w');
$ch = curl_init($getFile);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies');
$data = curl_exec($ch);
if(fwrite($fp,$data))
{
return true;
}
else
{
return false;
}
Run Code Online (Sandbox Code Playgroud)
感谢你的帮助。参考:http : //www.technologyworkshops.net/php/how-to-download-and-save-a-file-to-local-path-using-curl-t132.html
归档时间: |
|
查看次数: |
7324 次 |
最近记录: |