/** * @Route("/{id}", name="id") * @Request({"id": "integer", "key": "string", "pkey": "string"}) * @param integer $id File id * @param string $key session key * @param string $purchaseKey optional purchase key * @return BinaryFileResponse */ public function downloadAction($id, $key, $purchaseKey) { //todo return proper errors if (!($file = File::where(['id = ?', 'status = ?'], [$id, 1])->first())) { App::abort(404, __('File not found.')); } if (!$file->hasAccess(App::user())) { App::abort(403, __('Insufficient User Rights.')); } if (!$this->download->checkDownloadKey($file, $key, $purchaseKey)) { App::abort(400, __('Key not valid.')); } $file->updateDownloadCount(); // Generate response $response = new BinaryFileResponse($file->path); $response->headers->set('Content-Disposition', $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, basename($file->path), mb_convert_encoding(basename($file->path), 'ASCII'))); return $response; }