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


PHP StreamedResponse::send方法代码示例

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


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

示例1: uploadImageAction

 /**
  * Save uploaded image according to comur_image field configuration
  *
  * @param Request $request
  */
 public function uploadImageAction(Request $request)
 {
     $config = json_decode($request->request->get('config'), true);
     $uploadUrl = $config['uploadConfig']['uploadUrl'];
     $uploadUrl = substr($uploadUrl, -strlen('/')) === '/' ? $uploadUrl : $uploadUrl . '/';
     // We must use a streamed response because the UploadHandler echoes directly
     $response = new StreamedResponse();
     $webDir = $config['uploadConfig']['webDir'];
     $webDir = substr($webDir, -strlen('/')) === '/' ? $webDir : $webDir . '/';
     $filename = sha1(uniqid(mt_rand(), true));
     $thumbsDir = $this->container->getParameter('comur_image.thumbs_dir');
     $thumbSize = $this->container->getParameter('comur_image.media_lib_thumb_size');
     $galleryDir = $this->container->getParameter('comur_image.gallery_dir');
     $gThumbSize = $this->container->getParameter('comur_image.gallery_thumb_size');
     $ext = $request->files->get('image_upload_file')->getClientOriginalExtension();
     //('image_upload_file');
     $completeName = $filename . '.' . $ext;
     $controller = $this;
     $handlerConfig = array('upload_dir' => $uploadUrl, 'param_name' => 'image_upload_file', 'file_name' => $filename, 'upload_url' => $config['uploadConfig']['webDir'], 'min_width' => $config['cropConfig']['minWidth'], 'min_height' => $config['cropConfig']['minHeight'], 'image_versions' => array('thumbnail' => array('upload_dir' => $uploadUrl . $thumbsDir . '/', 'upload_url' => $config['uploadConfig']['webDir'] . '/' . $thumbsDir . '/', 'crop' => true, 'max_width' => $thumbSize, 'max_height' => $thumbSize)));
     $transDomain = $this->container->getParameter('comur_image.translation_domain');
     $errorMessages = array(1 => $this->get('translator')->trans('The uploaded file exceeds the upload_max_filesize directive in php.ini', array(), $transDomain), 2 => $this->get('translator')->trans('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', array(), $transDomain), 3 => $this->get('translator')->trans('The uploaded file was only partially uploaded', array(), $transDomain), 4 => $this->get('translator')->trans('No file was uploaded', array(), $transDomain), 6 => $this->get('translator')->trans('Missing a temporary folder', array(), $transDomain), 7 => $this->get('translator')->trans('Failed to write file to disk', array(), $transDomain), 8 => $this->get('translator')->trans('A PHP extension stopped the file upload', array(), $transDomain), 'post_max_size' => $this->get('translator')->trans('The uploaded file exceeds the post_max_size directive in php.ini', array(), $transDomain), 'max_file_size' => $this->get('translator')->trans('File is too big', array(), $transDomain), 'min_file_size' => $this->get('translator')->trans('File is too small', array(), $transDomain), 'accept_file_types' => $this->get('translator')->trans('Filetype not allowed', array(), $transDomain), 'max_number_of_files' => $this->get('translator')->trans('Maximum number of files exceeded', array(), $transDomain), 'max_width' => $this->get('translator')->trans('Image exceeds maximum width', array(), $transDomain), 'min_width' => $this->get('translator')->trans('Image requires a minimum width (%min%)', array('%min%' => $config['cropConfig']['minWidth']), $transDomain), 'max_height' => $this->get('translator')->trans('Image exceeds maximum height', array(), $transDomain), 'min_height' => $this->get('translator')->trans('Image requires a minimum height (%min%)', array('%min%' => $config['cropConfig']['minHeight']), $transDomain), 'abort' => $this->get('translator')->trans('File upload aborted', array(), $transDomain), 'image_resize' => $this->get('translator')->trans('Failed to resize image', array(), $transDomain));
     $response->setCallback(function () use($handlerConfig, $errorMessages) {
         new UploadHandler($handlerConfig, true, $errorMessages);
     });
     return $response->send();
 }
开发者ID:desmax,项目名称:ComurImageBundle,代码行数:31,代码来源:UploadController.php

示例2: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $uri = $request->path();
     $uri_arr = explode("/", $uri);
     if (in_array($uri, $this->noAuth)) {
         return $next($request);
     } else {
         if ($uri_arr[0] == "stream") {
             $res = $this->permissionForStream($request, $next, $uri_arr[2]);
             if ($res['status'] == "2") {
                 header('Content-Type: text/event-stream');
                 header('Cache-Control: no-cache');
                 $response = new StreamedResponse();
                 $response->setCallback(function () use($res) {
                     $output = json_encode($res);
                     echo "data:" . $output . "\n\n";
                     flush();
                     //sleep(1);
                 });
                 $response->send();
                 exit;
             } else {
                 return $next($request);
             }
         } else {
             $this->_init_($request);
             return $this->permissionToAccess($request, $next);
         }
     }
 }
开发者ID:saran-github,项目名称:repos,代码行数:37,代码来源:AuthenticateRequest.php

示例3: stream

 /**
  * Export the workbook.
  *
  * @param null|string $filename
  *
  * @throws \Exception
  * @return mixed|void
  */
 public function stream($filename = null)
 {
     $filename = $this->getFilename($filename);
     $output = $this->getExportable()->getDriver()->getOutputFromHtml($this->convertToHtml($this->getExportable()));
     $response = new StreamedResponse(function () use($output) {
         echo $output;
     }, 200, ['Content-Type' => 'application/pdf', 'Content-Disposition' => 'inline; filename="' . $filename . '.' . $this->getExtension() . '"']);
     return $response->send();
 }
开发者ID:ymnl007,项目名称:Clerk,代码行数:17,代码来源:Writer.php

示例4: fileAction

 /**
  * @Route(
  *     "/image/{node}",
  *     name="claro_image"
  * )
  */
 public function fileAction(ResourceNode $node)
 {
     $image = $this->get('claroline.manager.resource_manager')->getResourceFromNode($node);
     $response = new StreamedResponse();
     $path = $this->container->getParameter('claroline.param.files_directory') . DIRECTORY_SEPARATOR . $image->getHashName();
     $response->setCallBack(function () use($path) {
         readfile($path);
     });
     $response->headers->set('Content-Type', $node->getMimeType());
     return $response->send();
 }
开发者ID:claroline,项目名称:distribution,代码行数:17,代码来源:ImagePlayerController.php

示例5: export

 /**
  * CSV出力の共通処理
  * @param Application $app
  * @param Request $request
  * @param string $type CSV出力形式の種類
  * @return StreamedResponse
  */
 public function export(Application $app, Request $request, $type)
 {
     // タイムアウトを無効にする.
     set_time_limit(0);
     $response = new StreamedResponse();
     $response->setCallback(function () use($app, $request, $type) {
         $app['listing_ad_csv.service.listingad.data.creator']->create($app, $request, $type);
     });
     $response->headers->set('Content-Type', 'application/octet-stream');
     $response->headers->set('Content-Disposition', 'attachment; filename=' . $this->createFileName($type));
     $response->send();
     return $response;
 }
开发者ID:EC-CUBE,项目名称:listing-ad-plugin,代码行数:20,代码来源:ExportController.php

示例6: streamMediaAction

 /**
  * @EXT\Route(
  *     "resource/media/{node}",
  *     name="claro_file_get_media",
  *     options={"expose"=true}
  * )
  *
  * @param integer $id
  *
  * @return Response
  */
 public function streamMediaAction(ResourceNode $node)
 {
     $collection = new ResourceCollection(array($node));
     $this->checkAccess('OPEN', $collection);
     $file = $this->get('claroline.manager.resource_manager')->getResourceFromNode($node);
     $path = $this->container->getParameter('claroline.param.files_directory') . DIRECTORY_SEPARATOR . $file->getHashName();
     $response = new StreamedResponse();
     $response->setCallBack(function () use($path) {
         readfile($path);
     });
     $response->headers->set('Content-Type', $node->getMimeType());
     $response->send();
     return new Response();
 }
开发者ID:ChMat,项目名称:CoreBundle,代码行数:25,代码来源:FileController.php

示例7: download

 /**
  * @EXT\Route(
  *     "/download/{pdf}",
  *     name="claro_pdf_download",
  *     options={"expose"=true}
  * )
  * @EXT\ParamConverter(
  *     "pdf",
  *     class="ClarolinePdfGeneratorBundle:Pdf",
  *     options={"mapping": {"pdf": "guid"}}
  * )
  *
  * @param array $nodes
  * @param bool  $forceArchive
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function download(Pdf $pdf)
 {
     $response = new StreamedResponse();
     $file = $this->pdfManager->getFile($pdf);
     $response->setCallBack(function () use($file) {
         readfile($file);
     });
     $response->headers->set('Content-Transfer-Encoding', 'octet-stream');
     $response->headers->set('Content-Type', 'application/force-download');
     $response->headers->set('Content-Disposition', 'attachment; filename=' . urlencode($pdf->getName() . '.pdf'));
     $response->headers->set('Content-Type', 'application/pdf');
     $response->headers->set('Connection', 'close');
     $response->send();
 }
开发者ID:claroline,项目名称:distribution,代码行数:31,代码来源:PdfController.php

示例8: renderFile

 /**
  * {@inheritdoc}
  */
 public function renderFile(CRUDEntity $entity, $entityName, $field)
 {
     $targetPath = $this->getPath($entityName, $entity, $field);
     $fileName = $entity->get($field);
     $file = $targetPath . '/' . $fileName;
     $response = new Response('');
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mimeType = finfo_file($finfo, $file);
     finfo_close($finfo);
     $size = filesize($file);
     if ($fileName && file_exists($file)) {
         $response = new StreamedResponse(CRUDStreamedFileResponse::getStreamedFileFunction($file), 200, array('Content-Type' => $mimeType, 'Content-Disposition' => 'attachment; filename="' . $fileName . '"', 'Content-length' => $size));
         $response->send();
     }
     return $response;
 }
开发者ID:timfreiheit,项目名称:CRUDlex,代码行数:19,代码来源:CRUDSimpleFilesystemFileProcessor.php

示例9: downloadAction

 /**
  * @EXT\Route(
  *      "/download/invoice/{invoice}",
  *      name="invoice_download"
  * )
  *
  * @return Response
  */
 public function downloadAction(Invoice $invoice)
 {
     $user = $this->tokenStorage->getToken()->getUser();
     if ($invoice->getChart()->getOwner() !== $user && !$this->authorization->isGranted('ROLE_ADMIN')) {
         throw new AccessDeniedException();
     }
     $file = $this->invoiceManager->getPdf($invoice);
     $response = new StreamedResponse();
     $response->setCallBack(function () use($file) {
         readfile($file);
     });
     $response->headers->set('Content-Transfer-Encoding', 'octet-stream');
     $response->headers->set('Content-Type', 'application/force-download');
     $response->headers->set('Content-Disposition', 'attachment; filename=invoice-' . $invoice->getInvoiceNumber() . '.pdf');
     $response->headers->set('Content-Type', 'application/pdf');
     $response->headers->set('Connection', 'close');
     $response->send();
     return new Response();
 }
开发者ID:kitan1982,项目名称:InvoiceBundle,代码行数:27,代码来源:InvoiceController.php

示例10: recalculateAction

 public function recalculateAction(Player $me, $match)
 {
     $match = Match::get($match);
     // get a match even if it's deleted
     if (!$me->canEdit($match)) {
         throw new ForbiddenException("You are not allowed to edit that match.");
     }
     return $this->showConfirmationForm(function () use($match) {
         $response = new StreamedResponse();
         $response->headers->set('Content-Type', 'text/plain');
         $response->setCallback(function () use($match) {
             $this->recalculate($match);
         });
         $response->send();
     }, "Do you want to recalculate ELO history for all teams and matches after the specified match?", "ELO history recalculated", "Recalculate ELOs", function () use($match) {
         if ($match->isDeleted()) {
             return new RedirectResponse($match->getURL('list'));
         }
         return new RedirectResponse($match->getURL('show'));
     }, "Match/recalculate.html.twig", $noButton = true);
 }
开发者ID:blast007,项目名称:bzion,代码行数:21,代码来源:MatchController.php

示例11: export

 /**
  * 商品CSVの出力.
  *
  * @param Application $app
  * @param Request $request
  * @return StreamedResponse
  */
 public function export(Application $app, Request $request)
 {
     // タイムアウトを無効にする.
     set_time_limit(0);
     // sql loggerを無効にする.
     $em = $app['orm.em'];
     $em->getConfiguration()->setSQLLogger(null);
     $response = new StreamedResponse();
     $response->setCallback(function () use($app, $request) {
         // CSV種別を元に初期化.
         $app['eccube.service.csv.export']->initCsvType(CsvType::CSV_TYPE_PRODUCT);
         // ヘッダ行の出力.
         $app['eccube.service.csv.export']->exportHeader();
         // 商品データ検索用のクエリビルダを取得.
         $qb = $app['eccube.service.csv.export']->getProductQueryBuilder($request);
         // joinする場合はiterateが使えないため, select句をdistinctする.
         // http://qiita.com/suin/items/2b1e98105fa3ef89beb7
         // distinctのmysqlとpgsqlの挙動をあわせる.
         // http://uedatakeshi.blogspot.jp/2010/04/distinct-oeder-by-postgresmysql.html
         $qb->resetDQLPart('select')->resetDQLPart('orderBy')->select('p')->orderBy('p.update_date', 'DESC')->distinct();
         // データ行の出力.
         $app['eccube.service.csv.export']->setExportQueryBuilder($qb);
         $app['eccube.service.csv.export']->exportData(function ($entity, $csvService) {
             $Csvs = $csvService->getCsvs();
             /** @var $Product \Eccube\Entity\Product */
             $Product = $entity;
             /** @var $Product \Eccube\Entity\ProductClass[] */
             $ProductClassess = $Product->getProductClasses();
             foreach ($ProductClassess as $ProductClass) {
                 $row = array();
                 // CSV出力項目と合致するデータを取得.
                 foreach ($Csvs as $Csv) {
                     // 商品データを検索.
                     $data = $csvService->getData($Csv, $Product);
                     if (is_null($data)) {
                         // 商品規格情報を検索.
                         $data = $csvService->getData($Csv, $ProductClass);
                     }
                     $row[] = $data;
                 }
                 //$row[] = number_format(memory_get_usage(true));
                 // 出力.
                 $csvService->fputcsv($row);
             }
         });
     });
     $now = new \DateTime();
     $filename = 'product_' . $now->format('YmdHis') . '.csv';
     $response->headers->set('Content-Type', 'application/octet-stream');
     $response->headers->set('Content-Disposition', 'attachment; filename=' . $filename);
     $response->send();
     return $response;
 }
开发者ID:shhirose,项目名称:ec-cube,代码行数:60,代码来源:ProductController.php

示例12: staticFile

 /**
  * The controller for serving static files.
  *
  * @param Request $request
  * the current request
  * @param Application $app
  * the Silex application
  *
  * @return Response
  * redirects to the instance details page or 404 on invalid input
  */
 public function staticFile(Request $request, Application $app)
 {
     $fileParam = str_replace('..', '', $request->get('file'));
     $file = __DIR__ . '/../static/' . $fileParam;
     if (!$fileParam || !file_exists($file)) {
         return $this->getNotFoundPage($app, $app['translator']->trans('crudlex.resourceNotFound'));
     }
     $mimeTypes = new MimeTypes();
     $mimeType = $mimeTypes->getMimeType($file);
     $size = filesize($file);
     $streamedFileResponse = new StreamedFileResponse();
     $response = new StreamedResponse($streamedFileResponse->getStreamedFileFunction($file), 200, ['Content-Type' => $mimeType, 'Content-Disposition' => 'attachment; filename="' . basename($file) . '"', 'Content-length' => $size]);
     $response->setETag(filemtime($file))->setPublic()->isNotModified($request);
     $response->send();
     return $response;
 }
开发者ID:philiplb,项目名称:crudlex,代码行数:27,代码来源:ControllerProvider.php

示例13: exportShipping

 /**
  * 配送CSVの出力.
  *
  * @param Application $app
  * @param Request $request
  * @return StreamedResponse
  */
 public function exportShipping(Application $app, Request $request)
 {
     // タイムアウトを無効にする.
     set_time_limit(0);
     // sql loggerを無効にする.
     $em = $app['orm.em'];
     $em->getConfiguration()->setSQLLogger(null);
     $response = new StreamedResponse();
     $response->setCallback(function () use($app, $request) {
         // CSV種別を元に初期化.
         $app['eccube.service.csv.export']->initCsvType(CsvType::CSV_TYPE_SHIPPING);
         // ヘッダ行の出力.
         $app['eccube.service.csv.export']->exportHeader();
         // 受注データ検索用のクエリビルダを取得.
         $qb = $app['eccube.service.csv.export']->getOrderQueryBuilder($request);
         // データ行の出力.
         $app['eccube.service.csv.export']->setExportQueryBuilder($qb);
         $app['eccube.service.csv.export']->exportData(function ($entity, $csvService) {
             $Csvs = $csvService->getCsvs();
             /** @var $Order \Eccube\Entity\Order */
             $Order = $entity;
             /** @var $Shippings \Eccube\Entity\Shipping[] */
             $Shippings = $Order->getShippings();
             foreach ($Shippings as $Shipping) {
                 /** @var $ShipmentItems \Eccube\Entity\ShipmentItem */
                 $ShipmentItems = $Shipping->getShipmentItems();
                 foreach ($ShipmentItems as $ShipmentItem) {
                     $row = array();
                     // CSV出力項目と合致するデータを取得.
                     foreach ($Csvs as $Csv) {
                         // 受注データを検索.
                         $data = $csvService->getData($Csv, $Order);
                         if (is_null($data)) {
                             // 配送情報を検索.
                             $data = $csvService->getData($Csv, $Shipping);
                         }
                         if (is_null($data)) {
                             // 配送商品を検索.
                             $data = $csvService->getData($Csv, $ShipmentItem);
                         }
                         $row[] = $data;
                     }
                     //$row[] = number_format(memory_get_usage(true));
                     // 出力.
                     $csvService->fputcsv($row);
                 }
             }
         });
     });
     $now = new \DateTime();
     $filename = 'shipping_' . $now->format('YmdHis') . '.csv';
     $response->headers->set('Content-Type', 'application/octet-stream');
     $response->headers->set('Content-Disposition', 'attachment; filename=' . $filename);
     $response->send();
     return $response;
 }
开发者ID:shhirose,项目名称:ec-cube,代码行数:63,代码来源:OrderController.php

示例14: renderFile

 /**
  * {@inheritdoc}
  */
 public function renderFile(CRUDEntity $entity, $entityName, $field)
 {
     $targetPath = $this->getPath($entityName, $entity, $field);
     $fileName = $entity->get($field);
     $file = $targetPath . '/' . $fileName;
     $response = new Response('');
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mimeType = finfo_file($finfo, $file);
     finfo_close($finfo);
     $size = filesize($file);
     if ($fileName && file_exists($file)) {
         $response = new StreamedResponse(function () use($file) {
             set_time_limit(0);
             $handle = fopen($file, "rb");
             if ($handle !== false) {
                 $chunkSize = 1024 * 1024;
                 while (!feof($handle)) {
                     $buffer = fread($handle, $chunkSize);
                     echo $buffer;
                     flush();
                 }
                 fclose($handle);
             }
         }, 200, array('Content-Type' => $mimeType, 'Content-Disposition' => 'attachment; filename="' . $fileName . '"', 'Content-length' => $size));
         $response->send();
     }
     return $response;
 }
开发者ID:jchiotaka,项目名称:CRUDlex,代码行数:31,代码来源:CRUDSimpleFilesystemFileProcessor.php

示例15: exportAction

 /**
  * @EXT\Route(
  *     "/{workspace}/export",
  *     name="claro_workspace_export",
  *     options={"expose"=true}
  * )
  */
 public function exportAction(Workspace $workspace)
 {
     $archive = $this->container->get('claroline.manager.transfert_manager')->export($workspace);
     $fileName = $workspace->getCode() . '.zip';
     $mimeType = 'application/zip';
     $response = new StreamedResponse();
     $response->setCallBack(function () use($archive) {
         readfile($archive);
     });
     $response->headers->set('Content-Transfer-Encoding', 'octet-stream');
     $response->headers->set('Content-Type', 'application/force-download');
     $response->headers->set('Content-Disposition', 'attachment; filename=' . urlencode($fileName));
     $response->headers->set('Content-Length', filesize($archive));
     $response->headers->set('Content-Type', $mimeType);
     $response->headers->set('Connection', 'close');
     return $response->send();
 }
开发者ID:ChMat,项目名称:CoreBundle,代码行数:24,代码来源:WorkspaceController.php


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