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


PHP BinaryFileResponse::deleteFileAfterSend方法代码示例

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


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

示例1: downloadAction

 /**
  * 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;
 }
开发者ID:upenn-dag,项目名称:patient-repository,代码行数:19,代码来源:OutcomesController.php

示例2: index

 /**
  * Download file.
  *
  * @param Request $request
  * @param Response $response
  *
  * @return BinaryFileResponse
  */
 public function index(Request $request, Response $response)
 {
     $key = $request->query->get('key', 'gp');
     $download = $request->query->get('download', '1');
     if ($download == '1') {
         $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT;
     } else {
         $disposition = ResponseHeaderBag::DISPOSITION_INLINE;
     }
     $metaFile = new \Molengo\MetaFile($response);
     $info = $metaFile->getInfo($key);
     $dataFile = $metaFile->getDataFileName($key);
     $fileName = $info['filename'];
     $headers = ['Pragma' => 'public', 'Content-Description' => 'File Transfer', 'Content-Transfer-Encoding' => 'binary', 'Expires' => '0', 'Cache-Control' => 'must-revalidate, post-check = 0, pre-check = 0'];
     $fileResponse = new BinaryFileResponse($dataFile, 200, $headers);
     $fileResponse->deleteFileAfterSend(false);
     $fileResponse->setContentDisposition($disposition, $fileName);
     $fileResponse->prepare($this->request);
     $fileResponse->sendContent();
     // Delete meta file after download
     $metaFile->delete($key);
     return $fileResponse;
 }
开发者ID:odan,项目名称:molengo-webapp,代码行数:31,代码来源:FileController.php

示例3: testDeleteFileAfterSend

 public function testDeleteFileAfterSend()
 {
     $request = Request::create('/');
     $path = __DIR__ . '/File/Fixtures/to_delete';
     touch($path);
     $realPath = realpath($path);
     $this->assertFileExists($realPath);
     $response = new BinaryFileResponse($realPath);
     $response->deleteFileAfterSend(true);
     $response->prepare($request);
     $response->sendContent();
     $this->assertFileNotExists($path);
 }
开发者ID:alexbogo,项目名称:symfony,代码行数:13,代码来源:BinaryFileResponseTest.php

示例4: downloadAction

 /**
  * @Route("/download/{slug}.zip", requirements={"slug"=".+"})
  * @ParamConverter("entity", class="Cmfcmf\Module\MediaModule\Entity\Collection\CollectionEntity", options={"slug" = "slug"})
  *
  * @param Request          $request
  * @param CollectionEntity $entity
  *
  * @return array
  */
 public function downloadAction(CollectionEntity $entity)
 {
     if (!$this->get('cmfcmf_media_module.security_manager')->hasPermission($entity, 'download')) {
         throw new AccessDeniedException();
     }
     \CacheUtil::createLocalDir('CmfcmfMediaModule');
     $dir = \CacheUtil::getLocalDir('CmfcmfMediaModule');
     $path = $dir . '/' . uniqid(time(), true) . '.zip';
     $zip = new \ZipArchive();
     if ($zip->open($path, \ZipArchive::CREATE) !== true) {
         throw new ServiceUnavailableHttpException('Could not create zip archive!');
     }
     $mediaTypeCollection = $this->get('cmfcmf_media_module.media_type_collection');
     $hasContent = false;
     $usedFileNames = [];
     foreach ($entity->getMedia() as $media) {
         if ($media instanceof AbstractFileEntity && $media->isDownloadAllowed()) {
             /** @var UploadableMediaTypeInterface $mediaType */
             $mediaType = $mediaTypeCollection->getMediaTypeFromEntity($media);
             $filename = $media->getBeautifiedFileName();
             $originalFileExtension = pathinfo($filename, PATHINFO_EXTENSION);
             $originalFilename = pathinfo($filename, PATHINFO_BASENAME);
             for ($i = 1; in_array($filename, $usedFileNames, true); ++$i) {
                 $filename = "{$originalFilename} ({$i})" . (empty($originalFileExtension) ?: ".{$originalFileExtension}");
             }
             $zip->addFile($mediaType->getOriginalWithWatermark($media, 'path', false), $filename);
             $hasContent = true;
         }
     }
     if (!$hasContent) {
         $zip->addFromString('Empty Collection.txt', $this->__('Sorry, the collection appears to be empty or does not have any downloadable files.'));
     }
     $zip->close();
     $response = new BinaryFileResponse($path);
     $response->deleteFileAfterSend(true);
     return $response;
 }
开发者ID:shefik,项目名称:MediaModule,代码行数:46,代码来源:CollectionController.php

示例5: extractThemeAction

 /**
  * extract theme using locale and theme name.
  *
  * @param Request $request
  *
  * @return file to be downloaded
  */
 public function extractThemeAction(Request $request)
 {
     $themeName = $request->request->get('theme-name');
     $locale = $this->getDoctrine()->getRepository('PrestaShopBundle:Lang')->findOneByIsoCode($request->request->get('iso_code'))->getLocale();
     $theme = $this->get('prestashop.core.admin.theme.repository')->getInstanceByName($themeName);
     $tmpFolderPath = $this->get('kernel')->getCacheDir() . '/' . $themeName . '-tmp';
     $folderPath = $this->get('kernel')->getCacheDir() . '/' . $themeName;
     $zipFile = $folderPath . '.' . $locale . '.zip';
     // create the directories
     $fs = new Filesystem();
     $fs->mkdir($folderPath);
     $fs->mkdir($tmpFolderPath);
     $themeExtractor = $this->get('prestashop.translations.theme_extractor');
     $themeExtractor->setOutputPath($tmpFolderPath)->enableOverridingFromDatabase()->extract($theme, $locale);
     Flattenizer::flatten($tmpFolderPath . '/' . $locale, $folderPath . '/' . $locale, $locale);
     $this->get('prestashop.utils.zip_manager')->createArchive($zipFile, $folderPath);
     $response = new BinaryFileResponse($zipFile);
     $response->deleteFileAfterSend(true);
     $fs->remove($tmpFolderPath);
     $fs->remove($folderPath);
     return $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
 }
开发者ID:M03G,项目名称:PrestaShop,代码行数:29,代码来源:TranslationsController.php


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