我在控制器中编写了以下方法,该方法遍历文件夹中的所有文件并返回这些文件:
$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 中的 NotFoundHttpException .php第 161 行:
这些文件在存储中的原因是这些文件需要通过登录系统进行访问控制。
有没有可以处理这个问题的库?
我过去无数次做的是使用 readfile() 将文件流式传输给用户
希望对您有所帮助!