Created
March 9, 2018 08:05
-
-
Save dovidezra/d90b7ef58eebe034e798ffc11121f8de to your computer and use it in GitHub Desktop.
(php) download remote file with curl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function download_remote_file_with_curl($file_url, $save_to) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_POST, 0); | |
curl_setopt($ch, CURLOPT_URL, $file_url); | |
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36'); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$file_content = curl_exec($ch); | |
curl_close($ch); | |
$downloaded_file = fopen($save_to, 'w'); | |
fwrite($downloaded_file, $file_content); | |
fclose($downloaded_file); | |
} | |
download_remote_file_with_curl('https://example.com/example.txt', realpath("./") . '/btc.json'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment