I try to download file using a php-script from an URL like the following:
http://www.xcontest.org/track.php?t=2avxjsv1.igc
The code I use l
@Chris' answer works, but this seems to work better to download very large files without running out of memory, since it doesn't download the whole file into a variable before writing to disk:
$file_url = 'http://www.test.com/images/avatar.png';
$destination_path = "downloads/avatar.png";
$fp = fopen($destination_path, "w+");
$ch = curl_init($file_url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
$st_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
fclose($fp);
if($st_code == 200)
echo 'File downloaded successfully!';
else
echo 'Error downloading file!';
Source: https://www.kodingmadesimple.com/2018/02/php-download-file-from-url-curl.html