To download file to your server from external server where you have difficulty to have ssh enabled. So below is the curl code you can use for download.

set_time_limit(0);
$url = ‘Your Download URL’;
$fp = fopen (dirname(__FILE__) . ‘/localfile.tmp’, ‘w+’);//This is the file where we save the information
$ch = curl_init(str_replace(” “,”%20”,$url));//Here is the file we are downloading, replace spaces with %20
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp); // write curl response to file
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch); // get curl response
curl_close($ch);
fclose($fp);

One thought on “Download file Using curl”

Leave a Reply

Your email address will not be published. Required fields are marked *