trustXSendfileTypeHeader() public static method

Trust X-Sendfile-Type header.
public static trustXSendfileTypeHeader ( )
 /**
  * @param AttachmentDto $attachmentDto
  * @return BinaryFileResponse
  */
 protected function getFileDownloadResponse(AttachmentDto $attachmentDto)
 {
     $response = new BinaryFileResponse($attachmentDto->getFilePath());
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $attachmentDto->getFileName(), iconv('UTF-8', 'ASCII//TRANSLIT', $attachmentDto->getFileName()));
     return $response;
 }
 public function invoiceAction(Convention $convention, Request $request)
 {
     $registrations = $convention->getRegistrations();
     $zip = new ZipArchive();
     $title = $convention->getSlug();
     $filename = tempnam('/tmp/', 'ritsiGA-' . $title . '-');
     unlink($filename);
     if ($zip->open($filename, ZIPARCHIVE::CREATE) !== true) {
         throw new \Exception("cannot open <{$filename}>\n");
     }
     if (false === $zip->addEmptyDir($title)) {
         throw new \Exception("cannot add empty dir {$title}\n");
     }
     $route_dir = $this->container->getParameter('kernel.root_dir');
     foreach ($registrations as $registration) {
         $single_file = $route_dir . '/../private/documents/invoices/' . $registration->getId() . '.pdf';
         if (false === file_exists($single_file)) {
             continue;
         }
         $name = $registration->getId();
         if (false === $zip->addFile($single_file, implode('/', array($title, $name . '.pdf')))) {
             throw new \Exception("cannot add file\n");
         }
     }
     if (false === $zip->close()) {
         throw new \Exception("cannot close <{$filename}>\n");
     }
     $response = new BinaryFileResponse($filename);
     $response->trustXSendfileTypeHeader();
     $response->prepare($request);
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $convention->getSlug() . '-facturas.zip', iconv('UTF-8', 'ASCII//TRANSLIT', $convention->getSlug() . '-facturas.zip'));
     return $response;
 }
 /**
  * @Route("/video", name="video")
  *
  * Serving video allowing to handle Range and If-Range headers from the request.
  */
 public function videoServing(Request $request)
 {
     $file = $this->getParameter('assetic.write_to') . $this->container->get('templating.helper.assets')->getUrl('video/CreateSafe.mp4');
     $response = new BinaryFileResponse($file);
     BinaryFileResponse::trustXSendfileTypeHeader();
     $response->prepare($request);
     return $response;
 }
Exemplo n.º 4
0
 public function RenderAction(\SW\DocManagerBundle\Entity\Document $document)
 {
     $path = $document->getPath();
     $response = new BinaryFileResponse($path);
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $document->getName());
     return $response;
 }
Exemplo n.º 5
0
 public function applyHeaders(GetResponseEvent $event)
 {
     if (!$this->app['configuration.store']->isSetup()) {
         return;
     }
     if ($this->app['phraseanet.xsendfile-factory']->isXSendFileModeEnabled()) {
         BinaryFileResponse::trustXSendfileTypeHeader();
         $this->app['phraseanet.xsendfile-factory']->getMode()->setHeaders($event->getRequest());
     }
 }
Exemplo n.º 6
0
 public function testXSendfile()
 {
     $request = Request::create('/');
     $request->headers->set('X-Sendfile-Type', 'X-Sendfile');
     BinaryFileResponse::trustXSendfileTypeHeader();
     $response = BinaryFileResponse::create('README.md');
     $response->prepare($request);
     $this->expectOutputString('');
     $response->sendContent();
     $this->assertContains('README.md', $response->headers->get('X-Sendfile'));
 }
 /**
  * @Route("/{id}/download", name="article_review_download")
  * Función para descargar los artículos
  */
 public function downloadAction(ArticleReview $articleReview)
 {
     $this->denyAccessUnlessGranted('DOWNLOAD', $articleReview);
     $article = $articleReview->getArticle();
     $fileToDownload = $articleReview->getPath();
     $filename = $this->get('slugify')->slugify($article->getTitle()) . '.' . pathinfo($fileToDownload, PATHINFO_EXTENSION);
     $response = new BinaryFileResponse($fileToDownload);
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $filename, iconv('UTF-8', 'ASCII//TRANSLIT', $filename));
     return $response;
 }
 public function downloadAction()
 {
     $id = $this->request->query->get('id');
     /** @var Test $entity */
     $entity = $this->em->getRepository('AppBundle:Test')->find($id);
     $filename = sprintf("%s-%s-%s.%s", Slugger::slugify($entity->getSubject()->getName()), Slugger::slugify($entity->getSeason()), Slugger::slugify($entity->getYear()), pathinfo($entity->getFilename(), PATHINFO_EXTENSION));
     $fileToDownload = $this->get('vich_uploader.storage')->resolvePath($entity, 'file');
     $response = new BinaryFileResponse($fileToDownload);
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename, iconv('UTF-8', 'ASCII//TRANSLIT', $filename));
     return $response;
 }
Exemplo n.º 9
0
 public function afficherDocumentAction($id)
 {
     $item = $this->getDoctrine()->getRepository('GenericBundle:Formation')->find($id);
     if (!$item) {
         throw $this->createNotFoundException("File with ID {$id} does not exist!");
     }
     $pdfFile = $item->getDocument();
     //returns pdf file stored as mysql blob
     $response = new BinaryFileResponse($pdfFile);
     $response->trustXSendfileTypeHeader();
     $response->headers->set('Content-Type', 'application/pdf');
     return $response;
 }
Exemplo n.º 10
0
 /**
  * Serve the file using BinaryFileResponse.
  * 
  * @param string $date
  */
 public function vidAction($date)
 {
     $imageManager = $this->get('theapi_cctv.image_manager');
     try {
         $filename = $imageManager->getVideoFile($date);
         $response = new BinaryFileResponse($filename);
         $response->trustXSendfileTypeHeader();
         $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $filename, iconv('UTF-8', 'ASCII//TRANSLIT', $filename));
     } catch (\Exception $e) {
         throw $this->createNotFoundException($e->getMessage());
     }
     return $response;
 }
 /**
  * Force download of the specified filename
  *
  * @Route("/download/{filename}", requirements={"filename": ".+"})
  *
  * @param $filename
  * @return BinaryFileResponse
  * @throws NotFoundException
  */
 public function downloadAction($filename)
 {
     $filePath = sprintf('%s/../web/media/%s', $this->get('kernel')->getRootDir(), $filename);
     // Check if requested file exists.
     $fs = new Filesystem();
     if (!$fs->exists($filePath)) {
         throw $this->createNotFoundException();
     }
     // Prepare BinaryFileResponse
     $response = new BinaryFileResponse($filePath);
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
     return $response;
 }
 public function testDeliverFileWithFilenameAndDispositionAndXSendFileButFileNotInXAccelMapping()
 {
     BinaryFileResponse::trustXSendfileTypeHeader();
     $this->factory = new ServeFileResponseFactory(new \unicode());
     $mode = new NginxMode([['directory' => __DIR__ . '/../../../../files/', 'mount-point' => '/protected/']]);
     $request = Request::create('/');
     $mode->setHeaders($request);
     $file = __DIR__ . '/../../../../classes/PhraseanetTestCase.php';
     $response = $this->factory->deliverFile($file, 'PhraseanetTestCase.php', 'attachment');
     $response->prepare($request);
     $this->assertInstanceOf("Symfony\\Component\\HttpFoundation\\Response", $response);
     $this->assertEquals('attachment; filename="PhraseanetTestCase.php"', $response->headers->get('content-disposition'));
     $this->assertEquals(realpath($file), $response->headers->get('x-accel-redirect'));
 }
 /**
  * @ApiDoc(
  *  resource=true,
  *  description="Download a file test",
  *  https=true,
  *  requirements={
  *      {"name": "id", "dataType"="integer", "requirement"="\d+", "description"="Test id"},
  *  }
  * )
  * @Route("/tests/{id}/download")
  * @ParamConverter("test", class="AppBundle:Test", options={"mapping": {"id": "id"}})
  * @QueryParam(name="show", requirements="[01]", default="0", description="0: The file is downloaded, 1: The file is opened on the browser.")
  */
 public function getTestDownloadAction(Test $test, ParamFetcher $paramFetcher)
 {
     $filename = sprintf("%s-%s-%s.%s", Slugger::slugify($test->getSubject()->getName()), Slugger::slugify($test->getSeason()), Slugger::slugify($test->getYear()), pathinfo($test->getFilename(), PATHINFO_EXTENSION));
     $responseType = ResponseHeaderBag::DISPOSITION_ATTACHMENT;
     if ($page = $paramFetcher->get('show') === "1") {
         $responseType = ResponseHeaderBag::DISPOSITION_INLINE;
     }
     $fileToDownload = $this->get('vich_uploader.storage')->resolvePath($test, 'file');
     $response = new BinaryFileResponse($fileToDownload);
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition($responseType, $filename, iconv('UTF-8', 'ASCII//TRANSLIT', $filename));
     $em = $this->getDoctrine()->getManager();
     $test->incrementDownloads();
     $em->persist($test);
     $em->flush();
     return $response;
 }
Exemplo n.º 14
0
 /**
  * Serve a file by forcing the download
  *
  * @Route("/download/{filename}", name="download_file", requirements={"filename": ".+"})
  */
 public function downloadFileAction($filename)
 {
     /**
      * $basePath can be either exposed (typically inside web/)
      * or "internal"
      */
     $basePath = $this->container->getParameter('kernel.root_dir') . '/Resources/uploads';
     $filePath = $basePath . '/' . $filename;
     // check if file exists
     $fs = new FileSystem();
     if (!$fs->exists($filePath)) {
         throw $this->createNotFoundException();
     }
     // prepare BinaryFileResponse
     $response = new BinaryFileResponse($filePath);
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $filename, iconv('UTF-8', 'ASCII//TRANSLIT', $filename));
     return $response;
 }
Exemplo n.º 15
0
 public function downloadExistingFile($filename, $fileFullPath)
 {
     $sessionData = new Session();
     $fs = new Filesystem();
     $file = $fileFullPath . $filename;
     if ($fs->exists($file . '.docx')) {
         $fullPath = $file . '.docx';
     } elseif ($fs->exists($file . '.doc')) {
         $fullPath = $file . '.doc';
     } elseif ($fs->exists($file . '.pdf')) {
         $fullPath = $file . '.pdf';
     } else {
         $sessionData->getFlashBag()->add('alert_danger', 'File not found!');
         return false;
     }
     $response = new BinaryFileResponse($fullPath);
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $filename, iconv('UTF-8', 'ASCII//TRANSLIT', $filename));
     return $response;
 }
Exemplo n.º 16
0
 /**
  * @Route("/download.php",name="content_media_download")
  * @Method({"GET"})
  */
 public function downloadAction(Request $request)
 {
     $contentId = $request->get('contentId');
     /**
      * @var \Bellwether\BWCMSBundle\Entity\ContentRepository $contentRepository
      * @var \Bellwether\BWCMSBundle\Entity\ContentEntity $content
      */
     $contentRepository = $this->em()->getRepository('BWCMSBundle:ContentEntity');
     $content = $contentRepository->find($contentId);
     if ($content == null) {
         return new Response('Content not available', 500);
     }
     $downloadFile = $this->mm()->getFilePath($content->getFile(), true);
     $response = new BinaryFileResponse($downloadFile);
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $content->getFile(), iconv('UTF-8', 'ASCII//TRANSLIT', $content->getFile()));
     return $response;
 }
 private function getFileDownloadResponse(AttachmentDto $attachmentDto)
 {
     $response = new \Symfony\Component\HttpFoundation\BinaryFileResponse($attachmentDto->getFilePath());
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition(\Symfony\Component\HttpFoundation\ResponseHeaderBag::DISPOSITION_ATTACHMENT, $attachmentDto->getFileName(), iconv('UTF-8', 'ASCII//TRANSLIT', $attachmentDto->getFileName()));
     return $response;
 }
Exemplo n.º 18
0
 /**
  * @Route("/download/{slug}" , name="download_file")
  *
  */
 public function DownloadAction($slug)
 {
     $em = $this->getDoctrine()->getManager();
     $repo = $em->getRepository('UploadBundle:Fichier');
     $file = $repo->getFichier($slug);
     if (!$file || !$file->IsOpen()) {
         return $this->render('UploadBundle:File:file_not_found.html.twig');
     }
     $file->setDownload($file->getDownload() + 1);
     $em->persist($file);
     $em->flush();
     $response = new BinaryFileResponse($this->getParameter('upload_dir') . $file->getPath());
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $file->getName());
     return $response;
 }
Exemplo n.º 19
0
 /**
  * Handle a request for a file
  *
  * @param Request $request HTTP request
  * @return Response
  */
 public function getResponse(Request $request)
 {
     $response = new Response();
     $response->prepare($request);
     $path = implode('/', $request->getUrlSegments());
     if (!preg_match('~serve-file/e(\\d+)/l(\\d+)/d([ia])/c([01])/([a-zA-Z0-9\\-_]+)/(.*)$~', $path, $m)) {
         return $response->setStatusCode(400)->setContent('Malformatted request URL');
     }
     list(, $expires, $last_updated, $disposition, $use_cookie, $mac, $path_from_dataroot) = $m;
     if ($expires && $expires < time()) {
         return $response->setStatusCode(403)->setContent('URL has expired');
     }
     $hmac_data = array('expires' => (int) $expires, 'last_updated' => (int) $last_updated, 'disposition' => $disposition, 'path' => $path_from_dataroot, 'use_cookie' => (int) $use_cookie);
     if ((bool) $use_cookie) {
         $hmac_data['cookie'] = $this->getCookieValue($request);
     }
     ksort($hmac_data);
     $hmac = $this->crypto->getHmac($hmac_data);
     if (!$hmac->matchesToken($mac)) {
         return $response->setStatusCode(403)->setContent('HMAC mistmatch');
     }
     $dataroot = $this->config->getDataPath();
     $filenameonfilestore = "{$dataroot}{$path_from_dataroot}";
     if (!is_readable($filenameonfilestore)) {
         return $response->setStatusCode(404)->setContent('File not found');
     }
     $actual_last_updated = filemtime($filenameonfilestore);
     if ($actual_last_updated != $last_updated) {
         return $response->setStatusCode(403)->setContent('URL has expired');
     }
     $if_none_match = $request->headers->get('if_none_match');
     if (!empty($if_none_match)) {
         // strip mod_deflate suffixes
         $request->headers->set('if_none_match', str_replace('-gzip', '', $if_none_match));
     }
     $etag = '"' . $actual_last_updated . '"';
     $response->setPublic()->setEtag($etag);
     if ($response->isNotModified($request)) {
         return $response;
     }
     $public = $use_cookie ? false : true;
     $content_disposition = $disposition == 'i' ? 'inline' : 'attachment';
     $headers = ['Content-Type' => (new MimeTypeDetector())->getType($filenameonfilestore)];
     $response = new BinaryFileResponse($filenameonfilestore, 200, $headers, $public, $content_disposition);
     $sendfile_type = $this->config->getVolatile('X-Sendfile-Type');
     if ($sendfile_type) {
         $request->headers->set('X-Sendfile-Type', $sendfile_type);
         $mapping = (string) $this->config->getVolatile('X-Accel-Mapping');
         $request->headers->set('X-Accel-Mapping', $mapping);
         $response->trustXSendfileTypeHeader();
     }
     $response->prepare($request);
     if (empty($expires)) {
         $expires = strtotime('+1 year');
     }
     $expires_dt = (new DateTime())->setTimestamp($expires);
     $response->setExpires($expires_dt);
     $response->setEtag($etag);
     return $response;
 }
 /**
  * @dataProvider getSampleXAccelMappings
  */
 public function testXAccelMapping($realpath, $mapping, $virtual)
 {
     $request = Request::create('/');
     $request->headers->set('X-Sendfile-Type', 'X-Accel-Redirect');
     $request->headers->set('X-Accel-Mapping', $mapping);
     $file = new FakeFile($realpath, __DIR__ . '/File/Fixtures/test');
     BinaryFileResponse::trustXSendfileTypeHeader();
     $response = new BinaryFileResponse($file);
     $reflection = new \ReflectionObject($response);
     $property = $reflection->getProperty('file');
     $property->setAccessible(true);
     $property->setValue($response, $file);
     $response->prepare($request);
     $this->assertEquals($virtual, $response->headers->get('X-Accel-Redirect'));
 }
Exemplo n.º 21
0
 /**
  * @ParamConverter("multimediaObject", class="PumukitSchemaBundle:MultimediaObject", options={"id" = "mmId"})
  */
 public function downloadAction(MultimediaObject $multimediaObject, Request $request)
 {
     $track = $multimediaObject->getTrackById($request->get('id'));
     $response = new BinaryFileResponse($track->getPath());
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, basename($track->getPath()), iconv('UTF-8', 'ASCII//TRANSLIT', basename($track->getPath())));
     return $response;
 }
Exemplo n.º 22
0
 /**
  * Sends a file. The intended use of this is strictly for file _downloads_
  *
  * @param  \SplFileInfo|string  $file
  * @param  string               $filename
  * @param  array                $headers
  *
  * @return BinaryFileResponse
  */
 public function sendFile($file, $filename, $headers = [])
 {
     if (is_string($file)) {
         // drop the contents into a temp file to pass to Symfony
         $fs = new Filesystem();
         $tmpFile = tempnam(sys_get_temp_dir(), 'test');
         $fs->dumpFile($tmpFile, $file);
         $file = $tmpFile;
     }
     $response = new BinaryFileResponse($file, 200, $headers);
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename, iconv('UTF-8', 'ASCII//TRANSLIT', $filename));
     return $response;
 }
Exemplo n.º 23
0
//--------------------------------------------------------------------------
$config = $app['config']['app'];
date_default_timezone_set($config['timezone']);
//--------------------------------------------------------------------------
// Register The Alias Loader
//--------------------------------------------------------------------------
$aliases = $config['aliases'];
AliasLoader::getInstance($aliases)->register();
//--------------------------------------------------------------------------
// Enable HTTP Method Override
//--------------------------------------------------------------------------
Request::enableHttpMethodParameterOverride();
//--------------------------------------------------------------------------
// Enable Trusting Of X-Sendfile Type Header
//--------------------------------------------------------------------------
BinaryFileResponse::trustXSendfileTypeHeader();
//--------------------------------------------------------------------------
// Register The Core Service Providers
//--------------------------------------------------------------------------
$providers = $config['providers'];
$app->getProviderRepository()->load($app, $providers);
//--------------------------------------------------------------------------
// Additional Middleware On Application
//--------------------------------------------------------------------------
App::middleware('Shared\\Http\\ContentGuard', array($app['config']['app.debug']));
//--------------------------------------------------------------------------
// Register Booted Start Files
//--------------------------------------------------------------------------
$app->booted(function () use($app, $env) {
    //--------------------------------------------------------------------------
    // Intialize The Language API
Exemplo n.º 24
0
 /**
  *
  * @ApiDoc(
  *     description = "Download snapshot file",
  *     parameters = {
  *          {
  *              "name" = "q",
  *              "description" = "Query Request Id to get the desired snapshot",
  *              "dataType" = "integer",
  *              "required" = true
  *          }, {
  *              "name" = "snapshot",
  *              "description" = "The desired snapshot to download, if absent the most recent will be returned",
  *              "dataType" = "string",
  *              "required" = false
  *          }
  *     }, statusCodes = {
  *          402 = "Credentials not valid"
  *     }
  * )
  *
  * @param Request $request
  * @return JsonResponse|BinaryFileResponse
  */
 public function downLoadSnapshotAction(Request $request)
 {
     $authChecker = $this->get("security.authorization_checker");
     $roles = $this->getParameter("qcharts.user_roles");
     $allow_demo_users = $this->getParameter("qcharts.allow_demo_users");
     $response = null;
     try {
         ApiController::checkCredentials($authChecker, $roles, "user", $allow_demo_users);
         $snapshotService = $this->get("qcharts.core.snapshot_service");
         $queryService = $this->get("qcharts.query");
         $queryRequest = $request->query->get("q");
         $snapshotName = $request->query->get("snapshot", null);
         $queryRequest = $queryService->getQueryRequestById($queryRequest);
         $file = $snapshotService->getSnapshotFile($queryRequest, $snapshotName);
         $response = new BinaryFileResponse($file);
         $response->trustXSendfileTypeHeader();
         $response->headers->set("Content-Type", "text/csv");
         $fileName = substr($file->getFilename(), 0, -4);
         $fileName = "{$snapshotService->formatSnapshotName($queryRequest, $fileName)}.csv";
         $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $fileName, iconv('UTF-8', 'ASCII//TRANSLIT', $fileName));
     } catch (InvalidCredentialsException $e) {
         $response = new JsonResponse(ApiController::getNotValidCredentials());
     } catch (InstanceNotFoundException $e) {
         $response = new JsonResponse(["status" => $e->getCode(), "textStatus" => $e->getMessage()]);
     } catch (SnapshotException $e) {
         $response = new JsonResponse(["status" => $e->getCode(), "textStatus" => $e->getMessage()]);
     } catch (NotFoundException $e) {
         $response = new JsonResponse(["status" => $e->getCode(), "textStatus" => $e->getMessage()]);
     } finally {
         return $response;
     }
 }
Exemplo n.º 25
0
 /**
  * @Route("/descargar_factura/{registration}", name="invoice_download")
  */
 public function downloadInvoiceAction(Registration $registration)
 {
     $this->get('kernel')->getRootDir();
     $fileToDownload = $this->get('kernel')->getRootDir() . '/../private/documents/invoices/' . $registration->getId() . '.pdf';
     $response = new BinaryFileResponse($fileToDownload);
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $registration->getConvention()->getName() . '_factura.pdf', iconv('UTF-8', 'ASCII//TRANSLIT', $registration->getId()));
     return $response;
 }
Exemplo n.º 26
0
 private function downloadFileAction($os)
 {
     /**
      * $basePath can be either exposed (typically inside web/)
      * or "internal".
      */
     $basePath = $this->container->getParameter('kernel.root_dir') . '/Resources/my_custom_folder';
     $dir = $this->get('kernel')->getRootDir() . "/../../Dropbox/quota/updates";
     $handle = fopen("{$dir}/updates.txt", "r");
     if ($handle) {
         $version = "0.0.0";
         $link = "";
         while (($line = fgets($handle)) !== false) {
             $s = explode('#', $line);
             if (version_compare($s[0], $version) == 1) {
                 $link = $s[1];
                 $version = $s[0];
             }
         }
         fclose($handle);
     } else {
         // error opening the file.
     }
     $a = explode("/", $link);
     $filename = trim(end($a));
     $filePath = "{$dir}/{$filename}";
     // check if file exists
     $fs = new FileSystem();
     if (!$fs->exists($filePath)) {
         throw $this->createNotFoundException();
     }
     $filename = "Quota_Setup_{$os}.exe";
     // prepare BinaryFileResponse
     $response = new BinaryFileResponse($filePath);
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $filename, iconv('UTF-8', 'ASCII//TRANSLIT', $filename));
     return $response;
 }
Exemplo n.º 27
0
 /**
  * @Route("/archive/{name}", name="archiveDownload")
  * @param $name
  * @return BinaryFileResponse
  */
 public function downloadArchiveAction($name)
 {
     $em = $this->getDoctrine()->getManager();
     $archive = $em->getRepository('SSEICSSBundle:RecruitApplyArchive')->findOneBy(['archiveFile' => $name]);
     if ($archive === null) {
         throw new ResourceNotFoundException();
     }
     $file = $this->container->getParameter('upload_destination') . '/' . $archive->getArchiveFile();
     $response = new BinaryFileResponse($file);
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $archive->getArchiveName(), iconv('UTF-8', 'ASCII//TRANSLIT', $archive->getArchiveName()));
     return $response;
 }