if (!$this->customer->isLogged()) {
$this->session->data['redirect'] = $this->url->link('account/download', '', 'SSL');
$this->redirect($this->url->link('account/login', '', 'SSL'));
}
$this->load->model('account/download');
if (isset($this->request->get['order_download_id'])) {
$order_download_id = $this->request->get['order_download_id'];
} else {
$order_download_id = 0;
}
$download_info = $this->model_account_download->getDownload($order_download_id);
if ($download_info) {
$file = DIR_DOWNLOAD . $download_info['filename'];
$mask = basename($download_info['mask']);
if (!headers_sent()) {
if (file_exists($file)) {
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . ($mask ? $mask : basename($file)) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
if (ob_get_level()) ob_end_clean();
readfile($file, 'rb');
$this->model_account_download->updateRemaining($this->request->get['order_download_id']);
exit;
} else {
exit('Error: Could not find file ' . $file . '!');
}
} else {
exit('Error: Headers already sent out!');
}
} else {
$this->redirect($this->url->link('account/download', '', 'SSL'));
}