Issue
I have a URL as following
www.domain.com/file.asp?File=peoples.csv
This URL force downloads the file when hit in browser but i want to download this file on my local path using CURL.
Is there any way, thanks for help
Solution
Ok, got the solution. Sharing my answer.
$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;
}
Thanks all for your help. Reference : http://www.technologyworkshops.net/php/how-to-download-and-save-a-file-to-local-path-using-curl-t132.html
Answered By - sfdeveloper Answer Checked By - Mildred Charles (WPSolving Admin)