Add multiple roots in elFinder with array an array

958 views Asked by At

I have a JSON decoded array as following that having paths to roots.

$file_path = json_decode($_REQUEST['file_path']);

As we know we can add multiple roots as follows.

$opts = array(
'roots' => array(
    array(
        'driver'        => 'LocalFileSystem',           // driver for accessing file system (REQUIRED)
        'path'          => 'path/to/files/first_root',  // path to files (REQUIRED)
        'URL'           => 'http://localhost/files/first_root/',   // URL to files (REQUIRED)
        'alias'         => 'First home', // The name to replace your actual path name. (OPTIONAL)
        'accessControl' => 'access'      // disable and hide dot starting files (OPTIONAL)
    ),
    array(
        'driver'        => 'LocalFileSystem',
        'path'          => 'path/to/files/second_root',
        'URL'           => 'http://localhost/files/second_root/',
        'alias'         => 'Second home'
    )
)

);

I want to add dynamically my array's paths as follows.

foreach ($file_path as $path){
$array_1[] = array(
    'driver'        => 'LocalFileSystem',           // driver for accessing file system (REQUIRED)
    'path'          => $path,                 // path to files (REQUIRED)
    'URL'           => $path, // URL to files (REQUIRED)
    'trashHash'     => 't1_Lw',                     // elFinder's hash of trash folder
    'winHashFix'    => DIRECTORY_SEPARATOR !== '/', // to make hash same to Linux one on windows too
    'uploadDeny'    => array('all', '*'),                // All Mimetypes not allowed to upload
    'uploadOrder'   => array('deny', 'allow'),      // allowed Mimetype `image` and `text/plain` only
    'accessControl' => 'access'                     // disable and hide dot starting files (OPTIONAL)
);

}

But the problem is this will add an additional key to the front of every object. as follows.

    array(0 =>
 array(
        'driver'        => 'LocalFileSystem',    
        'path'          => 'path/to/files/first_root', 
        'URL'           => 'http://localhost/files/first_root/', 
        'alias'         => 'First home',
        'accessControl' => 'access'
    ), 
1 =>
    array(
        'driver'        => 'LocalFileSystem',
        'path'          => 'path/to/files/second_root',
        'URL'           => 'http://localhost/files/second_root/',
        'alias'         => 'Second home'
    ));

How can I remove that additional array key or is there another way to accomplish this task in elFinder.

1

There are 1 answers

0
Lahiru Madusanka On

Finally i found a solution. hope this will help if some one get this issue.

Loop the $opts array and push data to 'roots' key and initiate as follows.

    $opts['roots'] = array();
foreach ($file_path as $path) {
    array_push($opts['roots'],array (
            'driver'        => 'LocalFileSystem',           // driver for accessing file system (REQUIRED)
            'path'          => "$path/",                 // path to files (REQUIRED)
            'URL'           => "$path", // URL to files (REQUIRED)
            'trashHash'     => 't1_Lw',                     // elFinder's hash of trash folder
            'winHashFix'    => DIRECTORY_SEPARATOR !== '/', // to make hash same to Linux one on windows too
            'uploadDeny'    => array('all', '*'),                // All Mimetypes not allowed to upload
            'uploadOrder'   => array('deny', 'allow'),      // allowed Mimetype `image` and `text/plain` only
            'accessControl' => 'access'                     // disable and hide dot starting files (OPTIONAL)
        )
    );
}

$connector = new elFinderConnector(new elFinder($opts));
$connector->run();