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
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
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
May info below helps you.
curl your_url >your_file_path
and wget may also helps you slove this porblem. input:
wget your_url
You can use curl URL >file_path
, curl -o file_path URL
, or curl -O URL
. The latter command will take the filename from the URL and use it to store the downloaded data.
For example, curl -O https://example.com/search/clothes.html
will create a clothes.html file with the data downloaded from https://example.com/search/clothes.html.