Author: Niklas Fiekas (niklas.fiekas@tu-clausthal.de)
Author: stealth35 (stealth35-php@live.fr)
Author: Igor Wiedler (igor@wiedler.ch)
Author: Jordan Alliot (jordan.alliot@gmail.com)
Author: Sergey Linnik (linniksa@gmail.com)
Inheritance: extends Response
 /**
  * @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;
 }
Esempio n. 2
0
 public function connect(Application $app)
 {
     $route = $app['controllers_factory'];
     $route->get('{repo}/tree/{commitishPath}/', $treeController = function ($repo, $commitishPath = '') use($app) {
         $repository = $app['git']->getRepositoryFromName($app['git.repos'], $repo);
         if (!$commitishPath) {
             $commitishPath = $repository->getHead();
         }
         list($branch, $tree) = $app['util.routing']->parseCommitishPathParam($commitishPath, $repo);
         list($branch, $tree) = $app['util.repository']->extractRef($repository, $branch, $tree);
         $files = $repository->getTree($tree ? "{$branch}:\"{$tree}\"/" : $branch);
         $breadcrumbs = $app['util.view']->getBreadcrumbs($tree);
         $parent = null;
         if (($slash = strrpos($tree, '/')) !== false) {
             $parent = substr($tree, 0, $slash);
         } elseif (!empty($tree)) {
             $parent = '';
         }
         return $app['twig']->render('tree.twig', array('files' => $files->output(), 'repo' => $repo, 'branch' => $branch, 'path' => $tree ? $tree . '/' : $tree, 'parent' => $parent, 'breadcrumbs' => $breadcrumbs, 'branches' => $repository->getBranches(), 'tags' => $repository->getTags(), 'readme' => $app['util.repository']->getReadme($repository, $branch, $tree ? "{$tree}" : "")));
     })->assert('repo', $app['util.routing']->getRepositoryRegex())->assert('commitishPath', $app['util.routing']->getCommitishPathRegex())->convert('commitishPath', 'escaper.argument:escape')->bind('tree');
     $route->post('{repo}/tree/{branch}/search', function (Request $request, $repo, $branch = '', $tree = '') use($app) {
         $repository = $app['git']->getRepositoryFromName($app['git.repos'], $repo);
         if (!$branch) {
             $branch = $repository->getHead();
         }
         $query = $request->get('query');
         $breadcrumbs = array(array('dir' => 'Search results for: ' . $query, 'path' => ''));
         $results = $repository->searchTree($query, $branch);
         return $app['twig']->render('search.twig', array('results' => $results, 'repo' => $repo, 'branch' => $branch, 'path' => $tree, 'breadcrumbs' => $breadcrumbs, 'branches' => $repository->getBranches(), 'tags' => $repository->getTags(), 'query' => $query));
     })->assert('repo', $app['util.routing']->getRepositoryRegex())->assert('branch', $app['util.routing']->getBranchRegex())->convert('branch', 'escaper.argument:escape')->bind('search');
     $route->get('{repo}/{format}ball/{branch}', function ($repo, $format, $branch) use($app) {
         $repository = $app['git']->getRepositoryFromName($app['git.repos'], $repo);
         $tree = $repository->getBranchTree($branch);
         if (false === $tree) {
             return $app->abort(404, 'Invalid commit or tree reference: ' . $branch);
         }
         $file = $app['cache.archives'] . DIRECTORY_SEPARATOR . $repo . DIRECTORY_SEPARATOR . substr($tree, 0, 2) . DIRECTORY_SEPARATOR . substr($tree, 2) . '.' . $format;
         if (!file_exists($file)) {
             $repository->createArchive($tree, $file, $format);
         }
         /**
          * Generating name for downloading, lowercasing and removing all non
          * ascii and special characters
          */
         $filename = strtolower($branch);
         $filename = preg_replace('#[^a-z0-9]#', '_', $filename);
         $filename = preg_replace('#_+#', '_', $filename);
         $filename = $filename . '.' . $format;
         $response = new BinaryFileResponse($file);
         $response->setContentDisposition('attachment', $filename);
         return $response;
     })->assert('format', '(zip|tar)')->assert('repo', $app['util.routing']->getRepositoryRegex())->assert('branch', $app['util.routing']->getBranchRegex())->convert('branch', 'escaper.argument:escape')->bind('archive');
     $route->get('{repo}/{branch}/', function ($repo, $branch) use($app, $treeController) {
         return $treeController($repo, $branch);
     })->assert('repo', $app['util.routing']->getRepositoryRegex())->assert('branch', $app['util.routing']->getBranchRegex())->convert('branch', 'escaper.argument:escape')->bind('branch');
     $route->get('{repo}/', function ($repo) use($app, $treeController) {
         return $treeController($repo);
     })->assert('repo', $app['util.routing']->getRepositoryRegex())->bind('repository');
     return $route;
 }
 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;
 }
Esempio n. 4
0
 /**
  * Handle a request for a file
  *
  * @param Request $request HTTP request
  * @return Response
  */
 public function getResponse($request)
 {
     $response = new Response();
     $response->prepare($request);
     $path = implode('/', $request->getUrlSegments());
     if (!preg_match('~download-file/g(\\d+)$~', $path, $m)) {
         return $response->setStatusCode(400)->setContent('Malformatted request URL');
     }
     $this->application->start();
     $guid = (int) $m[1];
     $file = get_entity($guid);
     if (!$file instanceof ElggFile) {
         return $response->setStatusCode(404)->setContent("File with guid {$guid} does not exist");
     }
     $filenameonfilestore = $file->getFilenameOnFilestore();
     if (!is_readable($filenameonfilestore)) {
         return $response->setStatusCode(404)->setContent('File not found');
     }
     $last_updated = filemtime($filenameonfilestore);
     $etag = '"' . $last_updated . '"';
     $response->setPublic()->setEtag($etag);
     if ($response->isNotModified($request)) {
         return $response;
     }
     $response = new BinaryFileResponse($filenameonfilestore, 200, array(), false, 'attachment');
     $response->prepare($request);
     $expires = strtotime('+1 year');
     $expires_dt = (new DateTime())->setTimestamp($expires);
     $response->setExpires($expires_dt);
     $response->setEtag($etag);
     return $response;
 }
Esempio n. 5
0
 /**
  * Create a new file download response.
  *
  * @param  SplFileInfo|string  $file
  * @param  int  $status
  * @param  array  $headers
  * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
  */
 public static function download($file, $name = null, $headers = array())
 {
     $response = new BinaryFileResponse($file, 200, $headers, true, 'attachment');
     if (!is_null($name)) {
         return $response->setContentDisposition('attachment', $name);
     }
     return $response;
 }
 /**
  * @Route("/exchange/{file}.{_format}", defaults={"_format"="json"}, name="exchange")
  * @Method({"GET"})
  *
  * @param string $file 
  * @return void
  * @author Fran Iglesias
  */
 public function exchangeAction($file)
 {
     $file = $this->get('kernel')->getRootDir() . '/../var/exchange/' . $file . '.json';
     $response = new BinaryFileResponse($file);
     $response->setTtl(0);
     $response->headers->set('Content-Type', 'application/json');
     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;
 }
 public function loadApp()
 {
     $filename = 'stock-nth.apk';
     $headers = array();
     $disposition = 'attachment';
     $response = new BinaryFileResponse(storage_path() . '/' . $filename, 200, $headers, true);
     return $response->setContentDisposition($disposition, $filename, Str::ascii($filename));
 }
 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;
 }
Esempio n. 10
0
 /**
  * Create a new file download response.
  *
  * @param  \SplFileInfo|string  $file
  * @param  string  $name
  * @param  array   $headers
  * @param  null|string  $disposition
  * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
  */
 public static function download($file, $name = null, array $headers = array(), $disposition = 'attachment')
 {
     $response = new BinaryFileResponse($file, 200, $headers, true, $disposition);
     if (!is_null($name)) {
         return $response->setContentDisposition($disposition, $name, Str::ascii($name));
     }
     return $response;
 }
 public function downloadAction(Application $app, Request $request, $fileId)
 {
     $repo = $app->getFileRepository();
     $file = $repo->getById($fileId);
     $response = new BinaryFileResponse($file->getPath());
     $response->prepare(Request::createFromGlobals());
     $response->send();
 }
 /**
  * @Route("/image/show/{id}", name="image_show")
  */
 public function showImageAction(Image $image = null)
 {
     if ($image) {
         $response = new BinaryFileResponse($image->getAbsolutePath());
         $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $image->getName());
         return $response;
     } else {
         throw new NotFoundHttpException();
     }
 }
 /**
  * @param Request $request
  *
  * @return BinaryFileResponse
  *
  * @throws HttpException
  */
 public function downloadAction(Request $request)
 {
     $document = new \SplFileInfo($this->resources . '/' . $request->get('fileName'));
     if (!$document->isReadable()) {
         throw new HttpException(404);
     }
     $response = new BinaryFileResponse($document);
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $document->getFilename());
     return $response;
 }
 /**
  * @param Request $request
  *
  * @return BinaryFileResponse
  *
  * @throws HttpException
  */
 public function downloadDocumentAction(Request $request)
 {
     $fileName = $request->get('fileName');
     $document = $this->meetings->findDocument($fileName);
     if (!$document) {
         throw new HttpException(404);
     }
     $response = new BinaryFileResponse($document);
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $document->getFilename());
     return $response;
 }
 /**
  * {@inheritdoc}
  */
 public function deliverFile($file, $filename = '', $disposition = self::DISPOSITION_INLINE, $mimeType = null, $cacheDuration = 0)
 {
     $response = new BinaryFileResponse($file);
     $response->setContentDisposition($disposition, $this->sanitizeFilename($filename), $this->sanitizeFilenameFallback($filename));
     $response->setMaxAge($cacheDuration);
     $response->setPrivate();
     if (null !== $mimeType) {
         $response->headers->set('Content-Type', $mimeType);
     }
     return $response;
 }
Esempio n. 16
0
 public function getPdfContent(FileInterface $file)
 {
     if ($file != null) {
         if (strpos($file->getMimeType(), 'pdf') !== false) {
             $response = new BinaryFileResponse($this->fileService->getFilepath($file));
             $text = $this->pdfToString($response->getFile());
             return $text;
         }
     }
     return '';
 }
 /**
  * @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;
 }
Esempio n. 18
0
 public function render(Request $request, Response $response, array $args)
 {
     $item = new Item($args['id']);
     $size = isset($args['size']) ? $args['size'] : 'o';
     $version = isset($args['version']) ? $args['version'] : null;
     $cacheFile = $item->getCachePath($size, $version);
     $fileResponse = new BinaryFileResponse($cacheFile);
     $fileResponse->headers->set('Content-Type', 'image/png');
     $fileResponse->setFile($cacheFile);
     $fileResponse->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $item->getTitle() . '.png');
     return $fileResponse;
 }
 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;
 }
 public function download(Application $app, Request $request)
 {
     $fs = new Filesystem();
     $file = $request->query->get('file');
     $fullPath = $this->config['uploads']['base_directory'] . '/' . $file;
     if (!$fs->exists($fullPath)) {
         return new Response(null, Response::HTTP_NOT_FOUND);
     }
     $response = new BinaryFileResponse($fullPath);
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, basename($fullPath));
     return $response;
 }
Esempio n. 21
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;
 }
Esempio n. 22
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;
 }
 /**
  * Download dataset.
  *
  * @param Request $request
  * @return Response
  */
 public function downloadAction(Request $request)
 {
     $manager = $this->get("accard.outcomes.manager");
     $givenFilename = $request->get("file");
     $filename = $manager->generateExportFilePath($givenFilename);
     if (!$givenFilename || !file_exists($filename) || !is_readable($filename)) {
         throw $this->createNotFoundException("Requested file is invalid, you may only download a file one time before it is deleted.");
     }
     $response = new BinaryFileResponse($filename);
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $givenFilename);
     $response->deleteFileAfterSend(true);
     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;
 }
Esempio n. 25
0
 public function download(VirtualProductOrderDownloadResponseEvent $event)
 {
     $orderProduct = $event->getOrderProduct();
     if ($orderProduct->getVirtualDocument()) {
         // try to get the file
         $path = THELIA_ROOT . ConfigQuery::read('documents_library_path', 'local/media/documents') . DS . "product" . DS . $orderProduct->getVirtualDocument();
         if (!is_file($path) || !is_readable($path)) {
             throw new \ErrorException(Translator::getInstance()->trans("The file [%file] does not exist", ["%file" => $orderProduct->getId()]));
         }
         $response = new BinaryFileResponse($path);
         $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
         $event->setResponse($response);
     }
 }
Esempio n. 26
0
 /**
  * Handle a request for a file
  *
  * @param Request $request HTTP request
  * @return Response
  */
 public function getResponse($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');
     }
     $etag = '"' . $last_updated . '"';
     $response->setPublic()->setEtag($etag);
     if ($response->isNotModified($request)) {
         return $response;
     }
     // @todo: change to minimal boot without plugins
     $this->application->bootCore();
     $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'] = _elgg_services()->session->getId();
     }
     ksort($hmac_data);
     $hmac = elgg_build_hmac($hmac_data);
     if (!$hmac->matchesToken($mac)) {
         return $response->setStatusCode(403)->setContent('HMAC mistmatch');
     }
     $dataroot = _elgg_services()->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');
     }
     $public = $use_cookie ? false : true;
     $content_disposition = $disposition == 'i' ? 'inline' : 'attachment';
     $response = new BinaryFileResponse($filenameonfilestore, 200, array(), $public, $content_disposition);
     $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;
 }
Esempio n. 27
0
 public function issueFileAction(IssueFile $issueFile)
 {
     $fileManager = $this->get('jb_fileuploader.file_history.manager');
     $rootDir = $this->getParameter('kernel.root_dir');
     $assetHelper = $this->get('templating.helper.assets');
     $fileHistory = $fileManager->findOneByFileName($issueFile->getFile());
     $path = $rootDir . '/../web' . $fileManager->getUrl($fileHistory);
     $path = preg_replace('/\\?' . $assetHelper->getVersion() . '$/', '', $path);
     $response = new BinaryFileResponse($path);
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, preg_replace('/[[:^print:]]/', '_', $fileHistory->getOriginalName()));
     $event = new DownloadIssueFileEvent($issueFile);
     $dispatcher = $this->get('event_dispatcher');
     $dispatcher->dispatch(SiteEvents::DOWNLOAD_ISSUE_FILE, $event);
     return $response;
 }
 /**
  * Get resource
  *
  * @param Request $request
  * @param string  $id
  *
  * @return BinaryFileResponse
  */
 public function getAction(Request $request, $id)
 {
     $realId = $request->getSession()->get('_resource/' . $id);
     $class = $this->getParameter('rafrsr_resource.config')['class'];
     $resource = null;
     if ($class && $realId) {
         $resource = $this->getDoctrine()->getRepository($class)->find($realId);
     }
     if (!$resource) {
         throw new NotFoundHttpException();
     }
     // Generate response
     $response = new BinaryFileResponse($resource->getFile()->getRealPath());
     $response->setLastModified($resource->getUpdated());
     return $response;
 }
Esempio n. 29
0
 public function downloadAction($id)
 {
     $em = $this->getDoctrine()->getManager();
     $rep = $em->getRepository('GPSemellesBundle:Fichier');
     $fichier = $rep->find($id);
     if ($fichier) {
         $response = new BinaryFileResponse($fichier->getUploadDir() . '/' . $fichier->getFilename() . '.' . $fichier->getExtension());
         $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $fichier->getNom());
         return $response;
     } else {
         $request = $this->getRequest();
         $session = $request->getSession();
         $session->getFlashBag()->add('danger', 'Le fichier demandé est introuvable dans la base de données');
         return $this->redirectToRoute('semelles_index');
     }
 }
 /**
  * @param $id
  * @return Response
  * @Route("/reporte/download-file/{id}", name="ad_perfil_reporte_download")
  */
 public function downloadFileAction($id)
 {
     $em = $this->getDoctrine()->getManager();
     /** @var Archivo $file */
     $file = $em->getRepository('ADPerfilBundle:Archivo')->find($id);
     if (is_null($file)) {
         throw new NotFoundHttpException('Archivo No encontrado');
     }
     $response = new BinaryFileResponse($file->getPath());
     // Give the file a name:
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $file->getNombre());
     return $response;
 }