Is there a way to hide all root folders (hidden true) and control the visibility of the folders (hidden false) in the attribute array?
@iambudi Is it supposed to be combined with some authentication system? In order to set security restrictions, configure the config value dynamically on the connector side.
@nao-pon Yes, any sample or reference doc for this?
Using 'defaults' => ['hidden' => true]
and in the attributes => [] set to which folder with hidden => false.
Is that the correct way?
@iambudi If you control the volume display by authority, you should control it with the roots array instead of using the hidden attribute.
$opts = array(
'roots' => array()
);
if ($isAdmin) {
$opts['roots'][] = array(
'driver' => 'LocalFileSystem',
'path' => '/path/to/files/',
'URL' => 'http://localhost/to/files/'
);
}
if ($isUser) {
$opts['roots'][] = array(
'driver' => 'LocalFileSystem',
'path' => '/path/to/files1/',
'URL' => 'http://localhost/to/files1/'
);
}
// run elFinder
$connector = new elFinderConnector(new elFinder($opts));
$connector->run();
The folders are shared among users, not one folder dedicated to one user by root 'path' => '/path/to/files/' assignment.
I want user to see only specific folder as authorized.
Let's say i have the following folder structures and authorized to user A and B.
Documents (A)
Pictures (A, B)
--- Events (A, B)
--- --- School (A)
--- --- Public (B)
--- --- Others (A,B)
--- Design (A)
--- Family (Not A,B)
Downloads (Not A,B)
Applications (Not A,B)
So if user A open elfinder, All the root folders will be hidden and he can see only Documents and Pictures. At the same time user B open elfinder, he can only see folder Pictures.
The authorization is not stop there, It would also apply to the Pictures's sub folders.
So far for the root folders i use config defaults hidden set to true then i use attribute pattern to handle the sub folders authorization.
I need your suggest for a better way to handle this. This can make elFinder become more flexible to authorize to any level of sub folders.
@iambudi You can use an option accessControl of volume roots options.
For example, the function for A can be written as
/**
* Simple function to demonstrate how to control file access using "accessControl" callback.
* This method will disable accessing files/folders starting from '.' (dot)
*
* @param string $attr attribute name (read|write|locked|hidden)
* @param string $path absolute file path
* @param string $data value of volume option `accessControlData`
* @param object $volume elFinder volume driver object
* @param bool|null $isDir path is directory (true: directory, false: file, null: unknown)
* @param string $relpath file path relative to volume root directory started with directory separator
* @return bool|null
**/
function accessForA($attr, $path, $data, $volume, $isDir, $relpath) {
static $regpat;
if (!$regpat) {
$regpat = <<<'EOP'
~^
Documents(
/ # directory
|
/.+ # all of items
)
|
Pictures(
/ # directory
|
/
(
[^/]+ # files
|
Events # Pictures/Events
(
/ # directory
|
/[^/]+ # files
|
/
(
(
School # Pictures/Events/School
|
Others # Pictures/Events/Others
)
(
/ # directory
|
/[^/]+ # files
)
)
)
|
Design # Pictures/Design
(
/ # directory
|
/.+ # all of items
)
)
)
$~x
EOP;
}
$test = trim($relpath, '/');
if ($isDir) {
$test .= '/';
}
if (!preg_match($regpat, $test)) {
// set read+write to false, other (locked+hidden) set to true
return !($attr === 'read' || $attr === 'write');
}
$basename = basename($path);
return $basename[0] === '.' // if file/folder begins with '.' (dot)
&& strlen($relpath) !== 1 // but with out volume root
? !($attr == 'read' || $attr == 'write') // set read+write to false, other (locked+hidden) set to true
: null; // else elFinder decide it itself
}
@nao-pon Superb!. Working well. Thank you so much.