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


PHP Response::stream方法代码示例

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


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

示例1: getImage

 /**
  * Get image from storage
  * 
  * @param Request $request
  * @return file
  */
 public function getImage(Request $request)
 {
     /**
      * Check the cache
      */
     $cacheKey = 'image:' . $request->imageName . ':' . $request->imageExtension;
     /**
      * File cached
      */
     if (Cache::has($cacheKey)) {
         $imageMeta = Cache::get($cacheKey);
     } else {
         /**
          * Get META information
          */
         $imageMeta = Image::where(['url' => $request->imageName, 'image_extension' => $request->imageExtension])->first(['image_mime_type', 'image_size', 'id', 'updated_at', 'image_etag']);
         /**
          * File does not exist
          */
         if (empty($imageMeta) == TRUE) {
             App::abort(404);
         }
         /**
          * Save meta information to cache
          */
         Cache::forever($cacheKey, $imageMeta);
     }
     /**
      * Get filename
      */
     $filename = Helpers::getStorageFilename(env('APP_IMAGE_STORAGE_DIRECTORY', 'images'), $imageMeta->id);
     /**
      * Prepare stream
      */
     $stream = Storage::readStream($filename);
     /**
      * File headers
      */
     $headers = array('Content-Description' => 'File Transfer', 'Content-Type' => $imageMeta->image_mime_type, 'Content-Transfer-Encoding' => 'binary', 'Pragma' => 'public', 'Expires' => Carbon::createFromTimestamp(time() + 3600)->toRfc2822String(), 'Last-Modified' => $imageMeta->updated_at->toRfc2822String(), 'Etag' => $imageMeta->image_etag);
     /**
      * Response code cached
      */
     if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $imageMeta->image_etag || isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $imageMeta->updated_at->toRfc2822String()) {
         $responseCode = 304;
     } else {
         $responseCode = 200;
     }
     /**
      * Stream to browser
      */
     return Response::stream(function () use($stream) {
         fpassthru($stream);
     }, $responseCode, $headers);
 }
开发者ID:jdrda,项目名称:olapus,代码行数:60,代码来源:ImageController.php

示例2: getResponse

 /**
  * This code has been adapted the code at http://www.tuxxin.com/php-mp4-streaming.
  */
 public function getResponse()
 {
     $stream = fopen($this->asset->getFilename(), 'rb');
     $size = $length = $this->asset->getFilesize();
     $start = 0;
     $end = $size - 1;
     $code = 200;
     $headers = ['Content-Type' => $this->asset->getMimetype(), 'Accept-Ranges' => 'bytes'];
     if ($range = Request::header('Range')) {
         $c_start = $start;
         $c_end = $end;
         list(, $range) = explode('=', $range, 2);
         if (strpos($range, ',') !== false) {
             abort(416, null, ['Content-Range' => "bytes {$start}-{$end}/{$size}"]);
         }
         if ($range === '-') {
             $c_start = $size - substr($range, 1);
         } else {
             $range = explode('-', $range);
             $c_start = $range[0];
             $c_end = isset($range[1]) && is_numeric($range[1]) ? $range[1] : $size;
         }
         $c_end = $c_end > $end ? $end : $c_end;
         if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {
             abort(416, null, ['Content-Range' => "bytes {$start}-{$end}/{$size}"]);
         }
         $start = $c_start;
         $end = $c_end;
         $length = $end - $start + 1;
         fseek($stream, $start);
         $code = 206;
     }
     $headers['Content-Range'] = "bytes {$start}-{$end}/{$size}";
     $headers['Content-Length'] = $length;
     return Response::stream(function () use($stream, $end) {
         $buffer = 1024 * 8;
         while (!feof($stream) && ($p = ftell($stream)) <= $end) {
             if ($p + $buffer > $end) {
                 $buffer = $end - $p + 1;
             }
             set_time_limit(0);
             echo fread($stream, $buffer);
             flush();
         }
         fclose($stream);
     }, $code, $headers);
 }
开发者ID:boomcms,项目名称:boom-core,代码行数:50,代码来源:Stream.php

示例3: pages

 /**
  * Display a list of pages which use a given template.
  */
 public function pages(Template $template)
 {
     $pages = Helpers::getPages(['template' => $template, 'order' => 'title asc']);
     if ($this->request->route()->getParameter('format') !== 'csv') {
         return view($this->viewPrefix . '.pages', ['pages' => $pages, 'template' => $template]);
     }
     $headers = ['Content-type' => 'text/csv', 'Content-Disposition' => "attachment; filename=pages_with_template_{$template->getFilename()}.csv"];
     $callback = function () use($pages) {
         $fh = fopen('php://output', 'w');
         fputcsv($fh, ['Title', 'URL', 'Visible?', 'Last edited']);
         foreach ($pages as $p) {
             $data = ['title' => $p->getTitle(), 'url' => (string) $p->url(), 'visible' => $p->isVisible() ? 'Yes' : 'No', 'last_edited' => $p->getLastModified()->format('Y-m-d H:i:s')];
             fputcsv($fh, $data);
         }
         fclose($fh);
     };
     return Response::stream($callback, 200, $headers);
 }
开发者ID:imanghafoori1,项目名称:boom-core,代码行数:21,代码来源:Templates.php

示例4: getResponse

 public function getResponse()
 {
     $size = $fullsize = $this->asset->getFilesize();
     $stream = fopen($this->asset->getFilename(), 'r');
     $code = 200;
     $headers = ['Content-type' => $this->asset->getMimetype()];
     if ($range = Request::header('Range')) {
         $eqPos = strpos($range, '=');
         $toPos = strpos($range, '-');
         $unit = substr($range, 0, $eqPos);
         $start = intval(substr($range, $eqPos + 1, $toPos));
         $success = fseek($stream, $start);
         if ($success == 0) {
             $size = $fullsize - $start;
             $code = 206;
             $headers['Accept-Ranges'] = $unit;
             $headers['Content-Range'] = $unit . ' ' . $start . '-' . ($fullsize - 1) . '/' . $fullsize;
         }
     }
     $headers['Content-Length'] = $size;
     return Response::stream(function () use($stream) {
         fpassthru($stream);
     }, $code, $headers);
 }
开发者ID:robbytaylor,项目名称:boom-core,代码行数:24,代码来源:Stream.php

示例5: stream

 public function stream($video)
 {
     if (!Auth::user()->can('view-video')) {
         return view('errors.denied');
     }
     $filesystem = new Filesystem(new Adapter(base_path()));
     $location = '/files/video/' . $video;
     $stream = $filesystem->readStream($location);
     $headers = ["Content-Type" => $filesystem->getMimetype($location), "Content-Length" => $filesystem->getSize($location), "Content-disposition" => "attachment; filename=\"" . basename($location) . "\""];
     return Response::stream(function () use($stream) {
         fpassthru($stream);
     }, 200, $headers);
 }
开发者ID:nandeeshmp,项目名称:app,代码行数:13,代码来源:VideoController.php

示例6: showVideo

 /**
  * Created By Dara on 21/2/2016
  * get the video of the session
  */
 public function showVideo($videoName)
 {
     $path = storage_path('app') . '/' . $videoName;
     $file = File::get($path);
     $type = File::mimeType($path);
     $headers = ['Content-Type' => 'video/mp4', 'Content-Length' => File::size($path)];
     return Response::stream(function () use($path) {
         try {
             $stream = fopen($path, 'r');
             fpassthru($stream);
         } catch (Exception $e) {
             Log::error($e);
         }
     }, 200, $headers);
 }
开发者ID:emadmrz,项目名称:tinker,代码行数:19,代码来源:SessionController.php


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