laravel - Laravel 5 - 如何访问仅登录用户在存储中上传的文件夹、子文件夹、css、js
问题描述
我的 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
目录中
有没有办法允许在用户登录时评估存储目录中的每个文件和文件夹(不适用于猜测用户)。
解决方案
推荐阅读
- java - 是否可以在 PC 的 IDE Eclipse 和 Netbeans 中使用 Apache Tomcat 服务器?
- excel - 使用已由 COUNTIF 函数识别的基于 AVERAGEIF、MAXIF 等的单元格
- regex - 在正则表达式中匹配一个单词作为一个组
- python - 本守则有任何错误吗?如果是让我知道?
- wordpress - WordPress 和 SHA256 密码
- java - Java/Kotlin for Android - 硬编码对象或电子表格读取
- swift - 具有 4 个文本字段的自定义单元格
- reactjs - 使用 Chai\Mocha 设置进行单元测试时,如何让 JSDOM 与 typescript 一起使用?
- azure - 如何使用 Azure Python SDK 预配 Databricks 服务?
- javascript - 有什么办法可以在不连接这两个数组的情况下解决这个问题?