当前位置: 首页>>代码示例>>PHP>>正文


PHP HttpFoundation\BinaryFileResponse类代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\BinaryFileResponse的典型用法代码示例。如果您正苦于以下问题:PHP BinaryFileResponse类的具体用法?PHP BinaryFileResponse怎么用?PHP BinaryFileResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BinaryFileResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: invoiceAction

 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;
 }
开发者ID:aulasoftwarelibre,项目名称:ritsiga,代码行数:33,代码来源:ConventionCRUDController.php

示例2: connect

 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;
 }
开发者ID:rafasashi,项目名称:gitlist,代码行数:60,代码来源:TreeController.php

示例3: getResponse

 /**
  * 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;
 }
开发者ID:nirajkaushal,项目名称:Elgg,代码行数:38,代码来源:DownloadFileHandler.php

示例4: getFileDownloadResponse

 /**
  * @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;
 }
开发者ID:gitter-badger,项目名称:diamantedesk-application,代码行数:11,代码来源:ResponseHandlerTrait.php

示例5: download

 /**
  * 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;
 }
开发者ID:shinichi81,项目名称:laravel4demo,代码行数:16,代码来源:Response.php

示例6: exchangeAction

 /**
  * @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;
 }
开发者ID:franiglesias,项目名称:milhojas,代码行数:16,代码来源:DefaultController.php

示例7: videoServing

 /**
  * @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;
 }
开发者ID:DanieleMenara,项目名称:CreateSafe,代码行数:13,代码来源:DefaultController.php

示例8: loadApp

 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));
 }
开发者ID:themesanasang,项目名称:nth_supplier,代码行数:8,代码来源:HomeController.php

示例9: RenderAction

 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;
 }
开发者ID:adrienManikon,项目名称:docmanager,代码行数:8,代码来源:ViewController.php

示例10: download

 /**
  * 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;
 }
开发者ID:anthrotech,项目名称:laravel_sample,代码行数:17,代码来源:Response.php

示例11: downloadAction

 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();
 }
开发者ID:v03adk,项目名称:pdf-generation-server,代码行数:8,代码来源:FileController.php

示例12: showImageAction

 /**
  * @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();
     }
 }
开发者ID:stanislav-sulima,项目名称:levi9voter,代码行数:13,代码来源:UploadController.php

示例13: downloadAction

 /**
  * @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;
 }
开发者ID:WinterborneStickland,项目名称:parish-council-website,代码行数:17,代码来源:FinanceController.php

示例14: downloadDocumentAction

 /**
  * @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;
 }
开发者ID:WinterborneStickland,项目名称:parish-council-website,代码行数:18,代码来源:MeetingController.php

示例15: deliverFile

 /**
  * {@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;
 }
开发者ID:nlegoff,项目名称:Phraseanet,代码行数:14,代码来源:ServeFileResponseFactory.php


注:本文中的Symfony\Component\HttpFoundation\BinaryFileResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。