下载 .bin 文件的安全性

Security for downloading .bin files

我已经创建了 .bin 文件下载功能。我所有的 .bin 文件都存储在 'storage/app/files' 文件夹中。视图模板中的用户按下下载按钮,这会吸引处理所有下载功能的控制器(检查用户是否登录,文件是否存在于 'storage/app/files' 文件夹中)。我的问题是,将我所有的重要文件存储到此文件夹是否安全?我需要写一个 .htaccess 文件吗?

只有您的 public 文件夹(带有 index.php)应该可以访问,这是根目录(有时该目录被命名为 public_html)。

URL.

无法访问该目录之外的任何目录(如 storage/app/vendor 等) 如果您想保持对文件的控制,

"Everything" 必须先通过 index.php。 因此,为了提供像 storage/app/files/xxx.png 这样的资产,您应该使用控制器。该代码可能如下所示:

// SomeController.php
public function showAvatar(Request $request)
{
    // Select the `local` disk as defined in `config/filesystems.php`.
    $disk = Storage::disk('local');
    return response()->file($disk->path('files/xxx.png'));
}

然后您可以使用中间件或其他代码对这些文件进行限制。