Skip to content

Instantly share code, notes, and snippets.

@smarteist
Last active January 7, 2020 15:07
Show Gist options
  • Select an option

  • Save smarteist/03bd150d184f13d4383733e9eea14edd to your computer and use it in GitHub Desktop.

Select an option

Save smarteist/03bd150d184f13d4383733e9eea14edd to your computer and use it in GitHub Desktop.
download using php
<?php
// File to download.
$url = 'http://195.248.240.40/bs/q7HOz9I1yd3qoyoLjsQu/user.admin.hilet.2019-12-27_11-00-18_GMT.tar.gz';
// Open file
$fp = fopen($url, 'r');
file_put_contents(basename($url), $fp);
// Close file
fclose($fp);
?>
<?php
// resumable downloader
function download_file($url)
{
$fileName = basename($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if (file_exists($fileName)) {
$from = filesize($fileName);
curl_setopt($ch, CURLOPT_RANGE, $from . "-");
}
$fp = fopen($fileName, "a");
if (!$fp) {
exit;
}
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
curl_close($ch);
fclose($fp);
echo 'download finished';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment