[英]create specific upload folder based on user role and limit access to other folder in laravel elfinder
In my CMS , I am using Zizaco/entrust/ as an ACL manager and laravel-elfinder as a file manager and uploader. 在我的CMS中,我使用Zizaco / entrust /作为ACL管理器,使用laravel-elfinder作为文件管理器和上传器。
Both work fine and do not have any problem. 两者都工作正常,没有任何问题。
Now, I want to limit access of users that have Specified roles and Permissions to folders that elfinder manage them to upload or list files. 现在,我想将具有“指定角色”和“权限”的用户的访问权限限制到由elfinder管理他们以上传或列出文件的文件夹。
Globally in elfinder configuration file, we can set The dir
where to store the images (relative from public) like this : 全局在elfinder配置文件中,我们可以这样设置图像存储
dir
(相对于公共目录):
return array(
'dir' => ['upload']
);
In this case, All users by any Roles can access it and upload or other commom file operations. 在这种情况下,所有角色的所有用户都可以访问它并进行上传或其他公共文件操作。
But I want , after user login , if he wants to elfinder , only can access to folder same name as her username and he can not see or access other user folder. 但是我想要,在用户登录后,如果他要使用elfinder,则只能访问与她的用户名相同名称的文件夹,而他看不到或访问其他用户文件夹。
is it possible? 可能吗? if Yes please guide me.
如果是,请指导我。
According @Froxz guidance, I could solve the problem like this: 根据@Froxz的指导,我可以解决以下问题:
In Middleware that allow only admin user work with CMS, I wrote : 在仅允许管理员用户使用CMS的中间件中,我写道:
$username = Auth::user()->username;
if (!File::exists(public_path('upload').'/'.$username)) {
File::makeDirectory(public_path('upload').'/'.$username,0775);
}
Config::set('elfinder.dir',["upload/$username"]);
First , I created a directory same username of user , then set dir
option of elfinder configuration to that folder path. 首先,我创建了一个与user相同的用户名的目录,然后将elfinder配置的
dir
选项设置为该文件夹路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.