我有一个JSON解码数组,因为它具有通往根的路径。
$file_path = json_decode($_REQUEST['file_path']);
我们知道,我们可以添加多个根。
$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'
)
)
);
我想动态添加数组的路径如下。
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)
);
}
但问题是,这将为每个对象的正面添加一个附加键。如下。
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'
));
如何删除该附加数组键,或者有其他方法可以在Elfinder中完成此任务。
最后我找到了一个解决方案。希望如果有人得到这个问题,这将有所帮助。
循环$ opts数组,然后将数据推到"根"键,然后按以下方式启动。
$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();