sunhater / kcfinder

KCFinder web file manager
http://kcfinder.sunhater.com
402 stars 209 forks source link

Added ability to pass config manually #96

Open enumag opened 9 years ago

enumag commented 9 years ago

Personally I don't like the configuration via session thing. Instead I want to have my own logic in my app that would check privileges and such and then call the KCFinder directly. Here is what I use in my project:

<?php

use kcfinder\browser;
use kcfinder\uploader;

class FileManagerPresenter extends BasePresenter
{

    public function actionBrowse()
    {
        require_once $this->wwwDir . '/support/kcfinder/core/autoload.php';
        $browser = new browser($this->getConfig());
        $browser->action();
    }

    public function actionUpload()
    {
        require_once $this->wwwDir . '/support/kcfinder/core/autoload.php';
        $uploader = new uploader($this->getConfig());
        $uploader->upload();
    }

    private function getConfig()
    {
        // some logic to put the desired config together
    }

}

Now this means that the constructor should accept configuration array as an optional argument.

As a sideeffect since I have different URL it breaks autoloading, searching for lang files, javascript, css and such. I have fixed all that as well.

tomaswindsor commented 9 years ago

Since you are using [] array notation (PHP 5.4 feature), why not also use __DIR__ magical constant (PHP 5.3 feature) instead of dirname(__FILE__)?

enumag commented 9 years ago

The 5.4 array notation was not intended, KCFinder is currently compatible with 5.3 and it was not my intention to break it. Thanks for pointing it out.

enumag commented 9 years ago

@tomaswindsor Fixed compatibility with 5.3.