/** * Sends the file using the encryption manager with the php://output internal stream */ public function sendContent() { if (!$this->isSuccessful()) { parent::sendContent(); return; } $this->encryptionManager->decryptFile($this->file->getPathname(), 'php://output', $this->fileSize); }
/** * Download file. * * @param Request $request * @param Response $response * * @return BinaryFileResponse */ public function index(Request $request, Response $response) { $key = $request->query->get('key', 'gp'); $download = $request->query->get('download', '1'); if ($download == '1') { $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT; } else { $disposition = ResponseHeaderBag::DISPOSITION_INLINE; } $metaFile = new \Molengo\MetaFile($response); $info = $metaFile->getInfo($key); $dataFile = $metaFile->getDataFileName($key); $fileName = $info['filename']; $headers = ['Pragma' => 'public', 'Content-Description' => 'File Transfer', 'Content-Transfer-Encoding' => 'binary', 'Expires' => '0', 'Cache-Control' => 'must-revalidate, post-check = 0, pre-check = 0']; $fileResponse = new BinaryFileResponse($dataFile, 200, $headers); $fileResponse->deleteFileAfterSend(false); $fileResponse->setContentDisposition($disposition, $fileName); $fileResponse->prepare($this->request); $fileResponse->sendContent(); // Delete meta file after download $metaFile->delete($key); return $fileResponse; }
public function testDeleteFileAfterSend() { $request = Request::create('/'); $path = __DIR__ . '/File/Fixtures/to_delete'; touch($path); $realPath = realpath($path); $this->assertFileExists($realPath); $response = new BinaryFileResponse($realPath); $response->deleteFileAfterSend(true); $response->prepare($request); $response->sendContent(); $this->assertFileNotExists($path); }
public function sendContent() { echo $this->prepend; parent::sendContent(); echo $this->append; }