本文整理汇总了PHP中Symfony\Component\HttpFoundation\BinaryFileResponse::trustXSendfileTypeHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP BinaryFileResponse::trustXSendfileTypeHeader方法的具体用法?PHP BinaryFileResponse::trustXSendfileTypeHeader怎么用?PHP BinaryFileResponse::trustXSendfileTypeHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\BinaryFileResponse
的用法示例。
在下文中一共展示了BinaryFileResponse::trustXSendfileTypeHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: applyHeaders
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());
}
}
示例6: 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'));
}
示例7: downloadAction
/**
* @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;
}
示例8: downloadAction
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;
}
示例9: afficherDocumentAction
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;
}
示例10: vidAction
/**
* 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;
}
示例11: downloadAction
/**
* 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;
}
示例12: testDeliverFileWithFilenameAndDispositionAndXSendFileButFileNotInXAccelMapping
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'));
}
示例13: getTestDownloadAction
/**
* @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;
}
示例14: downloadFileAction
/**
* 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;
}
示例15: downloadExistingFile
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;
}