11-13-2007, 08:50 AM
|
#6 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Posts: 165
Thanks: 0
|
This can still be done using cURL however it is a bit of a pain, you can use the built-in callback functions to do the work storing the content and sending false when reached the required amount.
Salathe's suggestion will work when a website sends the correct http 1.1 headers that include the byte range acceptance header.
A snippet from a class i created a while back to work with this:
PHP Code:
function _header_callback($ch, $string) { $this->currentHeaders[] = $string; $count = strlen($string); if(preg_match("#Content-Type:#is", $string, $match)) { if(!preg_match("#Content-Type: text#is", $string, $match)) { print_r($this->currentHeaders); return 0; } } return $count; }
function _content_callback($ch, $string) { $this->currentDownload .= $string; $length = strlen($string); if(strlen($this->currentDownload) > $this->maxDownload) return 0; return $length; }
function _open($url) { $this->currentHeaders = array(); $this->currentDownload = ""; $this->currentHeaders[] = $url; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_USERAGENT, "Recipricol Backlink Checker");
curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this,'_header_callback')); //Callback for header, odd but works curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this,'_content_callback')); //Need a write function to READ? Stupid cURL
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_MAXREDIRS, 5); curl_exec($ch); curl_close($ch); $data = $this->currentDownload; return $data; }
|
|
|
|