$this->_downloadRepository->save($download);
$zip = $this->_configManager->getDirective('filesPath') . '/' . $file->getPath() . '/' . $file->getHash() . '.zip';
- //TODO: This may not work on all browser or something. We'll have to see. Also it may hog ram so...
$this->_response->setHeader('Content-Type', $file->getMimetype())
->setHeader('Content-Length', $file->getSize())
->setHeader('Content-Disposition', 'filename="' . $file->getFileName() . '";')
- ->setHeader('Content-Transfer-Encoding', 'binary')
- ->setBody(file_get_contents($zip))
- ->sendResponse();
+ ->download($zip);
+ exit();
}
private function notFound()
public function download($path)
{
- $fp = fopen($path, "rb");
- $this->sendHeaders();
- @ob_clean();
- rewind($fp);
- fpassthru($fp);
+ $this->sendResponse();
+ $fd = fopen($path, 'r');
+ if(!$fd) throw new Exception ('Failed to open file.');
+
+ while(!feof($fd)) {
+ $buffer = fread($fd, 2048);
+ print $buffer;
+ }
+ fclose ($fd);
+
+ exit();
}
}