Skip to content

Instantly share code, notes, and snippets.

@mah0001
Created June 15, 2012 01:23
Show Gist options
  • Save mah0001/2934086 to your computer and use it in GitHub Desktop.
Save mah0001/2934086 to your computer and use it in GitHub Desktop.
Partial downloading of files using CURL with PHP
/**
*
* 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