-
mrkzs
Newbie
-
Posts: 2
Threads: 1
Joined: Jul 2021
Reputation:
0
07-28-2021, 05:16 AM
Hi, I'm using elFinder(Open-source file manager for web) in Codeigniter 3, works fine but in Codeigniter 4.1.3 i can not integrate it and show me some error. I am beg someone help or suggestion. Thanks You.
Error Code:
Code: Class 'App\Libraries\elFinderConnector' not found
My code and configure bellow:
app\Libraries\Elfinder_lib.php
PHP Code: <?php namespace App\Libraries;
$root = __DIR__.'/../'; include_once $root.'ThirdParty/elfinder/elFinderConnector.class.php'; include_once $root.'ThirdParty/elfinder/elFinder.class.php'; include_once $root.'ThirdParty/elfinder/elFinderVolumeDriver.class.php'; include_once $root.'ThirdParty/elfinder/elFinderVolumeLocalFileSystem.class.php';
class Elfinder_lib { public function run($opts) { $connector = new elFinderConnector(new elFinder($opts)); return $connector->run(); } }
app\Controllers\News\FilemanagerController.php
PHP Code: <?php namespace App\Controllers\News;
use CodeIgniter\Controller; use Config\Services; use App\Libraries\Elfinder_lib;
class FilemanagerController extends Controller {
/** * Access to current session. * * @var \CodeIgniter\Session\Session */ protected $session;
/** * Authentication settings. */ protected $config;
//--------------------------------------------------------------------
public function __construct() { // start session $this->session = Services::session(); }
public function elfinderInit(){ $opts = array( // 'debug' => true, 'roots' => array( array( 'driver' => 'LocalFileSystem', 'path' => FCPATH . '/public/assets/uploads/images', 'URL' => base_url('public/assets/uploads/images'), 'uploadDeny' => array('all'),// All Mimetypes not allowed to upload 'uploadAllow' => array('image', 'text/plain', 'application/pdf'),// Mimetype `image` and `text/plain` allowed to upload 'uploadOrder' => array('deny', 'allow'), // allowed Mimetype `image` and `text/plain` only 'accessControl' => array($this, 'elfinderAccess'),// disable and hide dot starting files (OPTIONAL) // more elFinder options here ) ) ); $connector = new Elfinder_lib(); $connector->run($opts); }
}
app\Config\Routes.php
PHP Code: $routes->get('filemanager', 'News\FilemanagerController::elfinderInit');
app\Config\Autoload.php
PHP Code: public $psr4 = [ APP_NAMESPACE => APPPATH, // For custom app namespace 'Config' => APPPATH . 'Config', 'Elfinder' => APPPATH . 'ThirdParty/Elfinder', ];
elFinder Git link:
https://github.com/Studio-42/elFinder/tree/master/php
-
paulbalandan
External Auditor
-
Posts: 285
Threads: 6
Joined: Jul 2020
Reputation:
24
1. You can remove the include_once lines in your elfinder_lib class.
2. Elfinder is not using PSR4 to name their classes so you cannot do so either. You should use class map.
app/Config/Autoload.php
PHP Code: public $classmap = [ 'elFinderConnector' => APPPATH . 'ThirdParty/elfinder/elFinderConnector.class.php', // enumerate other elfinder classes ];
3. In your elfinder_lib class, when calling elFinderConnector you should qualify the call.
PHP Code: <?php namespace App\Libraries;
class Elfinder_lib { public function run($opts) { $connector = new \elFinderConnector(new \elFinder($opts)); return $connector->run(); } }
4. Alternative to #3, you can import them instead
PHP Code: <?php namespace App\Libraries;
use elFinderConnector; use elFinder;
class Elfinder_lib { public function run($opts) { $connector = new elFinderConnector(new elFinder($opts)); return $connector->run(); } }
-
nfaiz
Member
-
Posts: 53
Threads: 7
Joined: Apr 2015
Reputation:
3
(07-28-2021, 05:16 AM)mrkzs Wrote: Hi, I'm using elFinder(Open-source file manager for web) in Codeigniter 3, works fine but in Codeigniter 4.1.3 i can not integrate it and show me some error. I am beg someone help or suggestion. Thanks You.
Error Code:
Code: Class 'App\Libraries\elFinderConnector' not found
My code and configure bellow:
app\Libraries\Elfinder_lib.php
PHP Code: <?php namespace App\Libraries;
$root = __DIR__.'/../'; include_once $root.'ThirdParty/elfinder/elFinderConnector.class.php'; include_once $root.'ThirdParty/elfinder/elFinder.class.php'; include_once $root.'ThirdParty/elfinder/elFinderVolumeDriver.class.php'; include_once $root.'ThirdParty/elfinder/elFinderVolumeLocalFileSystem.class.php';
class Elfinder_lib { public function run($opts) { $connector = new elFinderConnector(new elFinder($opts)); return $connector->run(); } }
app\Controllers\News\FilemanagerController.php
PHP Code: <?php namespace App\Controllers\News;
use CodeIgniter\Controller; use Config\Services; use App\Libraries\Elfinder_lib;
class FilemanagerController extends Controller {
/** * Access to current session. * * @var \CodeIgniter\Session\Session */ protected $session;
/** * Authentication settings. */ protected $config;
//--------------------------------------------------------------------
public function __construct() { // start session $this->session = Services::session(); }
public function elfinderInit(){ $opts = array( // 'debug' => true, 'roots' => array( array( 'driver' => 'LocalFileSystem', 'path' => FCPATH . '/public/assets/uploads/images', 'URL' => base_url('public/assets/uploads/images'), 'uploadDeny' => array('all'),// All Mimetypes not allowed to upload 'uploadAllow' => array('image', 'text/plain', 'application/pdf'),// Mimetype `image` and `text/plain` allowed to upload 'uploadOrder' => array('deny', 'allow'), // allowed Mimetype `image` and `text/plain` only 'accessControl' => array($this, 'elfinderAccess'),// disable and hide dot starting files (OPTIONAL) // more elFinder options here ) ) ); $connector = new Elfinder_lib(); $connector->run($opts); }
}
app\Config\Routes.php
PHP Code: $routes->get('filemanager', 'News\FilemanagerController::elfinderInit');
app\Config\Autoload.php
PHP Code: public $psr4 = [ APP_NAMESPACE => APPPATH, // For custom app namespace 'Config' => APPPATH . 'Config', 'Elfinder' => APPPATH . 'ThirdParty/Elfinder', ];
elFinder Git link:
https://github.com/Studio-42/elFinder/tree/master/php
Maybe this gist can help
-
mrkzs
Newbie
-
Posts: 2
Threads: 1
Joined: Jul 2021
Reputation:
0
Thanks you brother @ nfaiz it's already solved by @ paulbalandan on this post subject but facing a new problem. I also test with your code but have a problem with upload image, all is ok such as directory listing, getFileCallback except upload image. In elFinder debug not show upload tab, In browser console show error with that connector link "Controller or its method is not found: \\App\\Controllers\\Filemanager::connector" but this controller file & function is unknown....
-
nfaiz
Member
-
Posts: 53
Threads: 7
Joined: Apr 2015
Reputation:
3
08-02-2021, 09:53 PM
(This post was last modified: 08-02-2021, 10:59 PM by nfaiz.)
(08-02-2021, 01:55 PM)mrkzs Wrote: Thanks you brother @nfaiz it's already solved by @paulbalandan on this post subject but facing a new problem. I also test with your code but have a problem with upload image, all is ok such as directory listing, getFileCallback except upload image. In elFinder debug not show upload tab, In browser console show error with that connector link "Controller or its method is not found: \\App\\Controllers\\Filemanager::connector" but this controller file & function is unknown....
If @ paulbalandan method works, just use it.
Mine is just an alternative method using composer and elFinder provided example. (php/connector.minimal.php and elfinder.html)
From the error stated, clearly the routes does not work.
For workaround;
- Remove both filemanager routes in app/Config/Routes.php
- Change Elfinder Controller class and file name to Filemanager
- Change init() method to index() and minimalConnector() method to connector() in new Filemanager controller (refer number 2).
Not sure how to use it using modules since route can't be used
p/s: Gist updated.
|