Search code examples
javascriptphpjquerybindelfinder

elfinder (a Javascript file manager plugin) bind action not fire in connector.php


function log() {
    $data = array(
        'folder_id' => 1,
        'user_id' => 1
    );

    $this->Folder_model->share($data);
}
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 album() {
    $opts = array(
        'bind' => array(
            'upload.presave' => array(
                'Plugin.AutoResize.onUpLoadPreSave'
            )
        ),
        'roots' => array(
            array(
                'driver' => 'LocalFileSystem',
                'alias' => 'Home',
                'path' => 'uploads/album/' . $this->user_id . '/',
                'URL' => site_url('uploads/album/' . $this->user_id),
                'uploadDeny' => array('all'),
                'uploadAllow' => array('image/jpeg', 'image/gif', 'image/png', 'image/bmp'),
                'uploadOrder' => array('deny', 'allow'),
                'accessControl' => array($this, 'access'),
                'plugin' => array(
                    'AutoResize' => array(
                        'enable' => true,
                        'maxWidth' => 2100,
                        'maxHeight' => 1500,
                        'quality' => 100
                    )
                ),
                'bind' => array(
                    'mkdir mkfile rename duplicate upload rm paste' => array($this, 'log')
                )
            )
        )
    );

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

The above is the class of connector, where album is the connector path used in frontend Jquery.

The problem is , since access control can trigger the function using array($this, 'access'), the syntax of array($this, 'log') in bind should be correct?

Howerver, I checked every action can not trigger the bind function, any way to debug? Thanks a lot


Solution

  • You can not use bind in roots options.

    function album() {
        $opts = array(
            'bind' => array(
                'upload.presave' => array(
                    'Plugin.AutoResize.onUpLoadPreSave'
                ),
                'mkdir mkfile rename duplicate upload rm paste' => array(
                    array($this, 'log')
                )
            ),
            'roots' => array(
                array(
                    'driver' => 'LocalFileSystem',
                    'alias' => 'Home',
                    'path' => 'uploads/album/' . $this->user_id . '/',
                    'URL' => site_url('uploads/album/' . $this->user_id),
                    'uploadDeny' => array('all'),
                    'uploadAllow' => array('image/jpeg', 'image/gif', 'image/png', 'image/bmp'),
                    'uploadOrder' => array('deny', 'allow'),
                    'accessControl' => array($this, 'access'),
                    'plugin' => array(
                        'AutoResize' => array(
                            'enable' => true,
                            'maxWidth' => 2100,
                            'maxHeight' => 1500,
                            'quality' => 100
                        )
                    )
                )
            )
        );