私の目標は、elFinderの初期化時に現在のアップロード ディレクトリを設定することです。たとえば、「ファイルのアップロード」リンクには、動的に生成された必要な作業ディレクトリがあります。ディレクトリを elFinder に渡すには?
3 に答える
はい、ハッシュを動的に取得したいです。
これはどう。
$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クラスをベースにしたシンプルなもの。
ステップ 1: //php で、ファイル パスからハッシュを作成します (例: dirname("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 options "id" => "myid" でボリューム ID を設定できます。
ステップ 2: JS から elfinder ウィンドウを呼び出す場合は、elfinder の初期化後、elfinder の onload イベントをバインドして、目的のディレクトリにジャンプします。この場合、php から取得した JS 変数 hasher に保存されます。
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);