public function receiveChunks($name, Closure $handler)
{
$result = false;
if ($this->request->file($name)) {
$file = $this->request->file($name);
$chunk = (int) $this->request->get('chunk', false);
$chunks = (int) $this->request->get('chunks', false);
$originalName = $this->request->get('name');
$filePath = $this->getPath() . '/' . $originalName . '.part';
$this->removeOldData($filePath);
$this->appendData($filePath, $file);
if ($chunk == $chunks - 1) {
$file = new UploadedFile($filePath, $originalName, 'blob', sizeof($filePath), UPLOAD_ERR_OK, true);
$result = $handler($file);
@unlink($filePath);
}
}
return $result;
}