Created
June 15, 2012 01:23
-
-
Save mah0001/2934086 to your computer and use it in GitHub Desktop.
Partial downloading of files using CURL with PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* 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