根据用户角色创建特定的上传文件夹,并限制对Laravel Elfinder中其他文件夹的访问 [英] create specific upload folder based on user role and limit access to other folder in laravel elfinder

查看:237
本文介绍了根据用户角色创建特定的上传文件夹,并限制对Laravel Elfinder中其他文件夹的访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的CMS中,我使用 Zizaco/entrust/作为ACL管理器和 laravel-elfinder 作为文件管理器和上传器.

In my CMS , I am using Zizaco/entrust/ as an ACL manager and laravel-elfinder as a file manager and uploader.

两者都能正常工作,没有任何问题.

Both work fine and do not have any problem.

现在,我想将具有指定角色和权限的用户的访问权限限制到由elfinder管理它们以上传或列出文件的文件夹.

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配置文件中,我们可以像这样设置dir存储图像(相对于公众)的位置:

Globally in elfinder configuration file, we can set The dir where to store the images (relative from public) like this :

return array(
    'dir' => ['upload']
);

在这种情况下,所有角色的所有用户都可以访问它并进行上传或其他公共文件操作.

In this case, All users by any Roles can access it and upload or other commom file operations.

但是我想,用户登录后,如果他想使用elfinder,则只能访问与她的用户名相同的文件夹,而他看不到或访问其他用户文件夹.

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.

有可能吗?如果是,请引导我.

is it possible? if Yes please guide me.

推荐答案

按照@Froxz指导,我可以解决以下问题:

According @Froxz guidance, I could solve the problem like this:

在仅允许管理员用户使用CMS的中间件中,我写道:

In Middleware that allow only admin user work with CMS, I wrote :

$username   =   Auth::user()->username;

if (!File::exists(public_path('upload').'/'.$username)) {
    File::makeDirectory(public_path('upload').'/'.$username,0775);
}
Config::set('elfinder.dir',["upload/$username"]);

首先,我创建了一个与user相同的用户名的目录,然后将elfinder配置的dir选项设置为该文件夹路径.

First , I created a directory same username of user , then set dir option of elfinder configuration to that folder path.

这篇关于根据用户角色创建特定的上传文件夹,并限制对Laravel Elfinder中其他文件夹的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆