我的 Laravel 存储目录中有一组目录。路径是\storage\app\public\docs。目录内docs有一组包含 HTML、CSS、JS 的文件夹。
如果用户登录,我想访问这些文件夹/文件。这是我的路线:
Route::get('storage/{directory}/{subdirectory}/{page}', function ($directory,$subdirectory,$page)
{
if(!Auth::check()){
die('Unauth access');
}
$path = storage_path('app/public/' . $directory.'/'.$subdirectory.'/'.$page);
if (!File::exists($path)) {
abort(404);
}
$file = File::get($path);
$type = File::mimeType($path);
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
return $response;
});
例子:
网址:
http://localhost:8000/storage/docs/62199911-74c61aaf688c0d374f23253218a12a9b81eaba4c/index.html
响应是加载成功。但是index.html中有一些外部css和js被调用。但它们没有加载到响应中。
js 和 css 包含在 css 和 js 目录中,包含在62199911-74c61aaf688c0d374f23253218a12a9b81eaba4c目录中
有没有办法允许在用户登录时评估存储目录中的每个文件和文件夹(不适用于猜测用户)。

