[英]Laravel - Retrieve Files from Storage for download
我在控制器内编写了以下方法,该方法将遍历文件夹中的所有文件并返回这些文件:
$ files = Storage :: files($ gallery);
public function showGallery($gallery)
{
$gallery = base64_decode($gallery);
$gallery_name = explode('/', $gallery);
$directories = Storage::directories($gallery);
$galleries = $gallery_name;
unset($galleries[0]);
unset($galleries[1]);
array_pop($galleries);
$files = Storage::files($gallery);
$locations = array();
foreach ($files as $file)
{
if($this->is_image($file))
{
$locations[] = Image::make(storage_path('app/' . $file))->encode( 'data-url' );
} else
{
$locations[] = storage_path('app/' . $file);
}
}
//dd($locations);
$data = [
'directories' => $directories,
'galleries' => $galleries,
'gallery_path' => $gallery,
'gallery_name' => end($gallery_name),
'locations' => $locations,
];
return view('private.user.gallery', $data);
}
之后,我将图像与其他文件类型分开。
我正在使用干预图像库来使图像公开可用和可见。
但是,当显示其他文件(如图标)(例如PDF,doc,mov文件)时,我陷入了困境。
当我单击前端的那些图标时,会出现此错误。
链接: http://lamotte.local/home/vagrant/projects/lamotte/storage/app/gallery/Brand/pdf-test.pdf
RouteCollection.php第161行中的NotFoundHttpException:
这些文件之所以存储,是因为这些文件需要通过登录系统进行访问控制。
是否有可以处理此问题的库?
我过去做过很多次的工作是使用readfile()将文件流式传输给用户
希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.