How to get current directory in elfinder?

有些话、适合烂在心里 提交于 2020-01-03 06:35:28

问题


I am using elfinder and I have a problem. I want to get current directory in elfinder but I can not.

EDITED: this is my connector. consist of my_function that called after upload, rename or mkdir commands and I want to get uploaded files path in specified place:

    <?php

error_reporting(0); // Set E_ALL for debuging
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderConnector.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinder.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeDriver.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeLocalFileSystem.class.php';

function access($attr, $path, $data, $volume) {
    return strpos(basename($path), '.') === 0       // if file/folder begins with '.' (dot)
        ? !($attr == 'read' || $attr == 'write')    // set read+write to false, other (locked+hidden) set to true
        :  null;                                    // else elFinder decide it itself
}


function my_function($cmd, $result, $args, $elfinder)
{
  // how to get current path here?
}

$opts = array(
  'bind' => array('upload rename mkdir' => 'my_function'),
    // 'debug' => true,
    'roots' => array(
        array(
            'driver'        => 'LocalFileSystem',   // driver for accessing file system (REQUIRED)
            'path'          => '../files/',         // path to files (REQUIRED)
            'URL'           => dirname($_SERVER['PHP_SELF']) . '/../files/', // URL to files (REQUIRED)
            'accessControl' => 'access'             // disable and hide dot starting files (OPTIONAL)
        ),
    )
);

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

回答1:


You can get items URL.

function my_function($cmd, $result, $args, $elfinder)
{
    // how to get current path here?
    foreach ($result['added'] as $file) {
        if (!empty($file['url']) && $file['url'] !=  1) {
            $url = $file['url'];
        }
    }
}

or Make inherent class ex elFinderVolumeMyLocalFileSystem

class elFinderVolumeMyLocalFileSystem extends elFinderVolumeLocalFileSystem
{
    public function decode($hash) {
        return parent::decode($hash);
    }
}

function my_function($cmd, $result, $args, $elfinder)
{
    // how to get current path here?
    foreach ($result['added'] as $file) {
        if ($volume = $elfinder->getVolume($file['hash'])) {
            $dir = $volume->decode($file['phash']);
        }
    }
}

$opts = array(
  'bind' => array('upload rename mkdir' => 'my_function'),
    // 'debug' => true,
    'roots' => array(
        array(
            'driver'        => 'MyLocalFileSystem',   // driver for accessing file system (REQUIRED)
            'path'          => '../files/',         // path to files (REQUIRED)
            'URL'           => dirname($_SERVER['PHP_SELF']) . '/../files/', // URL to files (REQUIRED)
            'accessControl' => 'access'             // disable and hide dot starting files (OPTIONAL)
        ),
    )
);


来源:https://stackoverflow.com/questions/28926500/how-to-get-current-directory-in-elfinder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!