Hello,
First many thanks for creating and uptading this famous tool, elFinder.
I would like to know, how can I show only some specific fodlers in elFinder tree.
The folder I want to show are in a PHP Array, and later I will get the values of theses arrays through SQL.
I know that this code doesn't work (I've got the error : "bad configuration of backend") But this code shows what I want to do :
function access($attr, $path, $data, $volume, $isDir, $relpath) {
$allowed = array("ihm","mpd","accords_conf","bdp",".tmb"); //Name of allowed folders
$basename = basename($path);
if (in_array($basename, $allowed) ) {
return ($attr == 'read' || $attr == 'write');
}
else {
return ($attr == 'hidden' || $attr == 'locked');
}
}
Any help please to achieve this ?
Thanks in advance =)
@Nick3523 May be... ( Not tested )
$allowed = array("ihm","mpd","accords_conf","bdp",".tmb");
$regex = '\/(?:' . join('|', array_map('preg_quote', $allowed)) . ')\/';
$basename = basename($path);
if (in_array($basename, $allowed) || preg_match($regex, $path)) {
( I do not considering performance. )
Thanks for your answere.
Unfortunately this doesn't work, but I managed a way to make it work :
I simply create an array called $forbidden that contains all folders in finally I do an array_dif between $forbidden and $allowed to keep the true forbbiden folders.
Here is the code if it may help someone
function filtrage($allowedFolders) {
$allfolders = array(".tmb",".quarantine"); //These are always forbbiden
foreach(glob('C:/src/datas/*', GLOB_ONLYDIR) as $dir) {
array_push($allfolders,basename($dir));
}
$forbidden = array_diff($allfolders, $allowedFolders );
return $forbidden;
}
function access($attr, $path, $data, $volume, $isDir, $relpath) {
$allowed = array("ecran_dynamique","requeteur","@azaz"); //To get with SQL Query later
$forbidden = filtrage($allowed);
$basename = basename($path);
return (in_array($basename, $forbidden)
&& strlen($relpath) !== 1)
? !($attr == 'read' || $attr == 'write') : null;
}
@Nick3523 For reference, If we consider Windows, it might be as follows.
$regex = '\' . DIRECTORY_SEPARATOR . '(?:' . join('|', array_map('preg_quote', $allowed)) . ')\ ' . DIRECTORY_SEPARATOR;
By the way, it was good that you could solve in another way. Since the access() function is called quite a lot, you can get good results by making the cache work with the filtrage() function.
@nao-pon Okay ! Thanks a lot for your help and advices, espcially about the cache, as I will use it with sql queries, it is a great idea to use cache for that :+1: