5

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

3
  • Please check this Question Commented Jul 24, 2013 at 7:17
  • I looking for help in php Commented Jul 24, 2013 at 7:22
  • This QUESTION will solve your problem. -[Download&Save File][1] [1]: stackoverflow.com/questions/10522138/… Commented Jul 24, 2013 at 12:00

3 Answers 3

5

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

Sign up to request clarification or add additional context in comments.

Comments

3

May info below helps you.

curl your_url >your_file_path

and wget may also helps you slove this porblem. input:

wget your_url

2 Comments

I looking for help in php
You haven't add any tags like 'php'.'CURL' in my mind is just a linux command.
3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.