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


PHP Storage::readStream方法代码示例

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


在下文中一共展示了Storage::readStream方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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