本文整理汇总了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);
}