_Note: this function uses the **Range** HTTP header to accomplish downloading in
parts. Not every server supports this header._
The proper use of this function is to call it once per request. The browser
should continue to send requests to Piwik which will in turn call this method
until the file has completely downloaded. In this way, the user can be informed
of a download's progress.
**Example Usage**
browser JavaScript
var downloadFile = function (isStart) {
var ajax = new ajaxHelper();
ajax.addParams({
module: 'MyPlugin',
action: 'myAction',
isStart: isStart ? 1 : 0
}, 'post');
ajax.setCallback(function (response) {
var progress = response.progress
...update progress...
downloadFile(false);
});
ajax.send();
}
downloadFile(true);
PHP controller action
public function myAction()
{
$outputPath = PIWIK_INCLUDE_PATH . '/tmp/averybigfile.zip';
$isStart = Common::getRequestVar('isStart', 1, 'int');
Http::downloadChunk("http://bigfiles.com/averybigfile.zip", $outputPath, $isStart == 1);
}
public static downloadChunk ( string $url, string $outputPath, boolean $isContinuation ) : array | ||
$url | string | The url to download from. |
$outputPath | string | The path to the file to save/append to. |
$isContinuation | boolean | `true` if this is the continuation of a download, or if we're starting a fresh one. |
return | array |