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


PHP BinaryFileResponse::create方法代码示例

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


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

示例1: testXSendfile

 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'));
 }
开发者ID:ragtek,项目名称:symfony,代码行数:11,代码来源:BinaryFileResponseTest.php

示例2: createPrivateFileDownloadResponse

 protected function createPrivateFileDownloadResponse(Request $request, $file)
 {
     $response = BinaryFileResponse::create($file['fullpath'], 200, array(), false);
     $response->trustXSendfileTypeHeader();
     $file['filename'] = urlencode($file['filename']);
     if (preg_match("/MSIE/i", $request->headers->get('User-Agent'))) {
         $response->headers->set('Content-Disposition', 'attachment; filename="' . $file['filename'] . '"');
     } else {
         $response->headers->set('Content-Disposition', "attachment; filename*=UTF-8''" . $file['filename']);
     }
     $mimeType = FileToolkit::getMimeTypeByExtension($file['ext']);
     if ($mimeType) {
         $response->headers->set('Content-Type', $mimeType);
     }
     return $response;
 }
开发者ID:latticet,项目名称:EduSoho_jb51,代码行数:16,代码来源:CourseMaterialController.php

示例3: renderFile

 /**
  *
  */
 protected function renderFile($file, $status = 200, $headers = array(), $public = true, $contentDisposition = null, $autoEtag = false, $autoLastModified = true)
 {
     // Check if a output action has be already performed
     $this->_checkIfPerformed();
     // Create a file response
     $fileResponse = \Symfony\Component\HttpFoundation\BinaryFileResponse::create($file, $status, $headers, $public, $contentDisposition, $autoEtag, $autoLastModified);
     // Add request informationen
     $fileResponse->prepare($this->application->requestStack->getCurrentRequest());
     // Replace response object
     $this->application->response = $fileResponse;
 }
开发者ID:gglnx,项目名称:nautik,代码行数:14,代码来源:Nautik.php

示例4: testAcceptRangeNotOverriden

 public function testAcceptRangeNotOverriden()
 {
     $request = Request::create('/', 'POST');
     $response = BinaryFileResponse::create(__DIR__ . '/File/Fixtures/test.gif');
     $response->headers->set('Accept-Ranges', 'foo');
     $response->prepare($request);
     $this->assertEquals('foo', $response->headers->get('Accept-Ranges'));
 }
开发者ID:GeorgeBroadley,项目名称:caffeine-vendor,代码行数:8,代码来源:BinaryFileResponseTest.php

示例5: downloadAction

 public function downloadAction(Request $request, $fileId)
 {
     $response = new Response();
     $user = $this->getCurrentUser();
     if (!$user->isLogin()) {
         return $this->redirect($this->generateUrl('login'));
     }
     $goods = $this->getThreadService()->getGoods($fileId);
     $file = $this->getFileService()->getFile($goods['fileId']);
     if ($goods['coin'] > 0 && $user['id'] != $file['userId']) {
         $trade = $this->getThreadService()->getTradeByUserIdAndGoodsId($user['id'], $goods['id']);
         if (!$trade) {
             return $this->createMessageResponse('info', '您未购买该附件!');
         }
     }
     $file = $this->getFileService()->getFile($goods['fileId']);
     $this->getThreadService()->waveGoodsHitNum($goods['id']);
     if (empty($file)) {
         throw $this->createNotFoundException();
     }
     $filename = $this->get('topxia.twig.web_extension')->getFilePath($file['uri']);
     $filename = substr($filename, 1);
     $filename = explode("?", $filename);
     $filename = $filename[0];
     $response = BinaryFileResponse::create($filename, 200, array(), false);
     $goods['title'] = urlencode($goods['title']);
     $goods['title'] = str_replace('+', '%20', $goods['title']);
     if (preg_match("/MSIE/i", $request->headers->get('User-Agent'))) {
         $response->headers->set('Content-Disposition', 'attachment; filename="' . $goods['title'] . '"');
     } else {
         $response->headers->set('Content-Disposition', "attachment; filename*=UTF-8''" . $goods['title']);
     }
     $response->headers->set('Content-type', "application/octet-stream");
     return $response;
 }
开发者ID:Loyalsoldier,项目名称:8000wei-v2,代码行数:35,代码来源:GroupThreadController.php

示例6: getLocalVideo

 public function getLocalVideo()
 {
     $fileId = $this->getParam("targetId");
     $user = $this->controller->getuserByToken($this->request);
     if (!$user->isLogin()) {
         return $this->createErrorResponse('not_login', "您尚未登录!");
     }
     $file = $this->getUploadFileService()->getFile($fileId);
     if (empty($file)) {
         return $this->createErrorResponse('error', "视频文件不存在!");
     }
     $response = BinaryFileResponse::create($file['fullpath'], 200, array(), false);
     $response->trustXSendfileTypeHeader();
     $mimeType = FileToolkit::getMimeTypeByExtension($file['ext']);
     if ($mimeType) {
         $response->headers->set('Content-Type', $mimeType);
     }
     return $response;
 }
开发者ID:robert-li-2015,项目名称:EduSoho,代码行数:19,代码来源:LessonProcessorImpl.php

示例7: serveImageAction

 /**
  * Serve the image from the templates-folder
  * @param  string                                               $filename
  * @param  string                                               $folderKey
  * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
  */
 public function serveImageAction($folderKey, $filename)
 {
     $folder = $this->getTemplateProviderService()->getFolderFrom($folderKey);
     if ($folder !== false) {
         $fullPath = $folder . $filename;
         $response = BinaryFileResponse::create($fullPath);
         $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE);
         $response->headers->set("Content-Type", "image");
         return $response;
     }
     throw new FileNotFoundException($filename);
 }
开发者ID:keynetic,项目名称:email-bundle,代码行数:18,代码来源:AzineEmailTemplateController.php

示例8: pageImageAction

 /**
  * @param  Request           $request
  * @param  Document          $document
  * @param  int               $page
  * @param  string            $size
  * @throws \RuntimeException
  * @return Response
  */
 public function pageImageAction(Request $request, Document $document, $page, $size)
 {
     $sizes = array('small' => 180, 'normal' => 700, 'large' => 1000);
     $width = $sizes[$size];
     $destination = realpath($this->container->getParameter('kernel.root_dir') . '/../web') . $request->getPathInfo();
     /** @var \Bangpound\Bundle\DocumentCloudBundle\BinaryDriver\GraphicsmagickDriver $driver */
     $driver = $this->get('bangpound_documentcloud.binary_driver.graphicsmagick');
     $filesystem = $this->get('filesystem');
     $filesystem->mkdir(dirname($destination));
     $arguments = array('convert', '+adjoin', '-define', 'pdf:use-cropbox=true', '-limit', 'memory', '256MiB', '-limit', 'map', '512MiB', '-density', '150', '-resize', $width . 'x', '-quality', 100, $document->getAbsolutePath() . '[' . ($page - 1) . ']', $destination);
     $builder = $driver->getProcessBuilderFactory();
     $process = $builder->create($arguments);
     $process->setEnv(array('PATH' => getenv('PATH')));
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
     return BinaryFileResponse::create($destination);
 }
开发者ID:bangpound,项目名称:documentcloud-bundle,代码行数:27,代码来源:ViewerController.php

示例9: localMediaAction

 public function localMediaAction(Request $request, $id, $token)
 {
     $file = $this->getUploadFileService()->getFile($id);
     if (empty($file)) {
         throw $this->createNotFoundException();
     }
     if (!in_array($file["type"], array("audio", "video"))) {
         throw $this->createAccessDeniedException();
     }
     $token = $this->getTokenService()->verifyToken('local.media', $token);
     if ($token['userId'] != $this->getCurrentUser()->getId()) {
         throw $this->createAccessDeniedException();
     }
     $response = BinaryFileResponse::create($file['fullpath'], 200, array(), false);
     $response->trustXSendfileTypeHeader();
     $mimeType = FileToolkit::getMimeTypeByExtension($file['ext']);
     if ($mimeType) {
         $response->headers->set('Content-Type', $mimeType);
     }
     return $response;
 }
开发者ID:fujianguo,项目名称:EduSoho,代码行数:21,代码来源:PlayerController.php


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