Skip to content

Instantly share code, notes, and snippets.

@artygrand
Created March 22, 2017 07:50
Show Gist options
  • Save artygrand/2fd92d2919d1274d5e0f6921eb64eaa7 to your computer and use it in GitHub Desktop.
Save artygrand/2fd92d2919d1274d5e0f6921eb64eaa7 to your computer and use it in GitHub Desktop.
Curl file loader
<?php
set_time_limit(0);
$file = dirname(__FILE__) . '/file.tgz';
$url = 'http://site/file.tgz';
$file_offset=filesize($file);
$file_offset=$file_offset-1024*4;
$fp = fopen($file,'ab+');
rewind($fp);
ftruncate($fp, $file_offset);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RESUME_FROM, $file_offset);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
curl_close($ch);
fclose($fp);
/*
$fp = fopen($file, 'w+');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
*/
echo 'loaded!';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment