Skip to content

Instantly share code, notes, and snippets.

@shakahl
Forked from mah0001/curl-partial-download.php
Last active August 29, 2015 14:13
Show Gist options
  • Save shakahl/b519d3a3954d22ac1740 to your computer and use it in GitHub Desktop.
Save shakahl/b519d3a3954d22ac1740 to your computer and use it in GitHub Desktop.
/**
*
* Using CURL to download partial content from a URL
*
* @url file URL to download
* @range_start Start range in bytes
* @range_end End range in bytes
*
*
* example: curl_get_content("http://www.example.org/some-file.zip",100,500)
*
**/
function curl_get_content($url,$range_start,$range_end)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HTTPHEADER, array ("Range: bytes=$range_start-$range_end"));
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment