Welcome Guest, Not a member yet? Register   Sign In
Class not found for elFinder(Open-source file manager for web) in Codeigniter 4
#1
Exclamation 

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
Reply
#2

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();
    }

Reply
#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  Smile
Reply
#4

Thanks you brother @nfaiz it's already solved by @paulbalandan on this post subject  Smile  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....
Reply
#5

(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  Smile  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;

  1. Remove both filemanager routes in app/Config/Routes.php
  2. Change Elfinder Controller class and file name to Filemanager
  3. 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  Sad

p/s: Gist updated.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB