elFinder:设置当前上传目录

elFinder: Set current upload directory

我的目标是在 elFinder 初始化时设置当前上传目录。例如,我的 "Upload files" link 具有动态生成的所需工作目录。如何将目录传递给elFinder?

elFinder 2.1 可以直接打开任何具有 URL 哈希的文件夹。

例如

Yes, I want to get hash dynamically.

这个怎么样。

$encode_func = function ($path, $root) {
    $p = $path == $root ? '' : substr($path, strlen($root)+1)
    if ($p === '')  {
        $p = DIRECTORY_SEPARATOR;
    }
    $hash = $this->crypt($p);
    $hash = strtr(base64_encode($hash), '+/=', '-_.');
    $hash = rtrim($hash, '.'); 
    return $hash;
};
$id   = '[uniqueId]_'; You must set same id into root option
$root = realpath('../image/data/');
$path = realpath('../image/data/product');
$hash = $id.$encode($path, $root);
$url_hash = '#elf_'.$hash;

基于 nao-pon 和 elfinder 的一些简单的东西 class。

第一步: //in php 从你的文件路径中生成哈希值,例如目录名("root/images/iphone/iphone-6S.jpg")。 大部分只是 base64_encode

function elfinder_hash_path($path)
{
        if ($path == '')
            $path = DIRECTORY_SEPARATOR;
        $hash = substr($path, strlen("root-name")+1);
        // hash is used as id in HTML that means it must contain vaild chars
        // make base64 html safe and append prefix in begining
        $hash = strtr(base64_encode($hash), '+/=', '-_.');
        // remove dots '.' at the end, before it was '=' in base64
        $hash = rtrim($hash, '.');
        // append volume id to make hash unique
        return "l1_". $hash;
}

"l1" 是 elfinder 中第一个本地文件系统的自动卷 ID。 否则,您可以在 connector.php 选项 "id" => "myid",

中设置卷 ID

第 2 步: 如果你从 JS 调用 elfinder window,那么在 elfinder 初始化之后, 绑定 elfinder onload 事件以跳转到您想要的目录。 在这种情况下,保存在 JS 变量哈希器中,从 php.

获取
var elf = $('#elfinder').elfinder({
    url : 'elfinder/php/connector.php',  // connector URL (REQUIRED)
    lang: 'sk',
    height: okno_vyska
}).elfinder('instance');

elf.bind('load', function(event) { elf.exec('open', hasher); });

更新:
elf.exec('open', hasher) 不起作用,如果散列的子目录在这个 js 会话中还没有打开,因此它不在缓存中,elfinder 什么都不做。
解决方法:要么使用
window.location.hash = hasher;
或者在 elf init

之前更新本地存储中最后使用的目录
localStorage.setItem('elfinder-lastdirelfinder', hasher);