简体   繁体   English

laravel防止未经身份验证的用户查看文件

[英]laravel prevent unauthenticated users from viewing the files

I want to try to make some route filter using pattern filter, but it's doesn't work. 我想尝试使用模式过滤器制作一些路由过滤器,但这是行不通的。 How to make a route to prevent unauthenticated users from viewing files on specific folder ? 如何进行路由以防止未经身份验证的用户查看特定文件夹中的文件?

Try this: 尝试这个:

Route::get('/directory/{file}', array('before' => 'auth', function($file)
{
    return public_path() . "/directory/$file";
}));

Change directory to whatever the directory is you are trying to protect. 更改directory到任何目录是你试图保护。 Also, I assumed the files you want to deal out are in your public directory. 另外,我假设您要处理的文件位于您的公共目录中。 That may need to be changed too, depending on your usage. 根据您的用法,可能还需要更改该设置。

Auth is a filter that is already created in a default install of Laravel. Auth是默认安装的Laravel中已经创建的过滤器。 It just makes sure they aren't a "guest." 这只是确保他们不是“客人”。 It will only let people access the directory if they are "logged in." 仅当人们“登录”时,它才允许人们访问目录。 I believe it looks for a cookie that Laravel sets when you log someone in. 我相信它会查找您登录某人时Laravel设置的Cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM