mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 12:14:36 +00:00
Merge pull request #615 from zachborboa/pr608
Implement Curl::setRange() and MultiCurl::setRange()
This commit is contained in:
+14
-3
@@ -309,7 +309,7 @@ class Curl
|
||||
if (is_file($download_filename) && $filesize = filesize($download_filename)) {
|
||||
$first_byte_position = $filesize;
|
||||
$range = $first_byte_position . '-';
|
||||
$this->setOpt(CURLOPT_RANGE, $range);
|
||||
$this->setRange($range);
|
||||
$this->fileHandle = fopen($download_filename, 'ab');
|
||||
} else {
|
||||
$this->fileHandle = fopen($download_filename, 'wb');
|
||||
@@ -326,7 +326,7 @@ class Curl
|
||||
};
|
||||
}
|
||||
|
||||
$this->setOpt(CURLOPT_FILE, $this->fileHandle);
|
||||
$this->setFile($this->fileHandle);
|
||||
$this->get($url);
|
||||
|
||||
return ! $this->error;
|
||||
@@ -1123,6 +1123,17 @@ class Curl
|
||||
$this->setOpt(CURLOPT_PROXY, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Range
|
||||
*
|
||||
* @access public
|
||||
* @param $range
|
||||
*/
|
||||
public function setRange($range)
|
||||
{
|
||||
$this->setOpt(CURLOPT_RANGE, $range);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Referer
|
||||
*
|
||||
@@ -1597,7 +1608,7 @@ class Curl
|
||||
|
||||
// Reset CURLOPT_FILE with STDOUT to avoid: "curl_exec(): CURLOPT_FILE
|
||||
// resource has gone away, resetting to default".
|
||||
$this->setOpt(CURLOPT_FILE, STDOUT);
|
||||
$this->setFile(STDOUT);
|
||||
|
||||
// Reset CURLOPT_RETURNTRANSFER to tell cURL to return subsequent
|
||||
// responses as the return value of curl_exec(). Without this,
|
||||
|
||||
+13
-2
@@ -102,7 +102,7 @@ class MultiCurl
|
||||
if (is_file($download_filename) && $filesize = filesize($download_filename)) {
|
||||
$first_byte_position = $filesize;
|
||||
$range = $first_byte_position . '-';
|
||||
$curl->setOpt(CURLOPT_RANGE, $range);
|
||||
$curl->setRange($range);
|
||||
$curl->fileHandle = fopen($download_filename, 'ab');
|
||||
|
||||
// Move the downloaded temporary file to the destination save path.
|
||||
@@ -122,7 +122,7 @@ class MultiCurl
|
||||
}
|
||||
}
|
||||
|
||||
$curl->setOpt(CURLOPT_FILE, $curl->fileHandle);
|
||||
$curl->setFile($curl->fileHandle);
|
||||
$curl->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
$curl->setOpt(CURLOPT_HTTPGET, true);
|
||||
return $curl;
|
||||
@@ -702,6 +702,17 @@ class MultiCurl
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Range
|
||||
*
|
||||
* @access public
|
||||
* @param $range
|
||||
*/
|
||||
public function setRange($range)
|
||||
{
|
||||
$this->setOpt(CURLOPT_RANGE, $range);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Referer
|
||||
*
|
||||
|
||||
@@ -3886,7 +3886,16 @@ class CurlTest extends \PHPUnit\Framework\TestCase
|
||||
$file = STDOUT;
|
||||
|
||||
$curl = new Curl();
|
||||
$curl->setFile(STDOUT);
|
||||
$curl->setFile($file);
|
||||
$this->assertEquals($file, $curl->getOpt(CURLOPT_FILE));
|
||||
}
|
||||
|
||||
public function testSetRange()
|
||||
{
|
||||
$range = '1000-';
|
||||
|
||||
$curl = new Curl();
|
||||
$curl->setRange($range);
|
||||
$this->assertEquals($range, $curl->getOpt(CURLOPT_RANGE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3397,7 +3397,17 @@ class MultiCurlTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$multi_curl = new MultiCurl();
|
||||
$this->assertNull($multi_curl->getOpt(CURLOPT_FILE));
|
||||
$multi_curl->setFile(STDOUT);
|
||||
$multi_curl->setFile($file);
|
||||
$this->assertEquals($file, $multi_curl->getOpt(CURLOPT_FILE));
|
||||
}
|
||||
|
||||
public function testSetRange()
|
||||
{
|
||||
$range = '1000-';
|
||||
|
||||
$multi_curl = new MultiCurl();
|
||||
$this->assertNull($multi_curl->getOpt(CURLOPT_RANGE));
|
||||
$multi_curl->setRange($range);
|
||||
$this->assertEquals($range, $multi_curl->getOpt(CURLOPT_RANGE));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user