scottb
scottb

Reputation: 41

Unable to open CKFinder - Invalid resource type

I'm trying to set up a new instance of CKFinder 3 (integrated with CKEditor) and am racking my brain trying to track down and resolve this problem. Sorry for the wall of text.

When I try to open the Browse window (as soon as the window is opened), I just get the loading throbber and the following log generated in the upload folder (I have debug logging turned on).

[2015-10-19 23:05:41] CKFinder.ERROR: exception 'CKSource\CKFinder\Exception\InvalidResourceTypeException' with message 'Invalid resource type: ' in C:\inetpub\wwwroot\*snip*\resources\other\ckfinder\core\connector\php\vendor\cksource\ckfinder\src\CKSource\CKFinder\Config.php:376

Stack trace:
#0 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\vendor\cksource\ckfinder\src\CKSource\CKFinder\ResourceType\ResourceTypeFactory.php(34): CKSource\CKFinder\Config->getResourceTypeNode('') 
#1 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\vendor\cksource\ckfinder\src\CKSource\CKFinder\Filesystem\Folder\WorkingFolder.php(96): CKSource\CKFinder\ResourceType\ResourceTypeFactory->getResourceType('') 
#2 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\vendor\cksource\ckfinder\src\CKSource\CKFinder\CKFinder.php(117): CKSource\CKFinder\Filesystem\Folder\WorkingFolder->__construct(Object(CKSource\CKFinder\CKFinder)) 
#3 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\vendor\pimple\pimple\src\Pimple\Container.php(112): CKSource\CKFinder\CKFinder->CKSource\CKFinder\{closure}(Object(CKSource\CKFinder\CKFinder)) 
#4 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\vendor\cksource\ckfinder\src\CKSource\CKFinder\CKFinder.php(288): Pimple\Container->offsetGet('working_folder') 
#5 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\vendor\cksource\ckfinder\src\CKSource\CKFinder\Command\CommandAbstract.php(68): CKSource\CKFinder\CKFinder->getWorkingFolder() 
#6 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\vendor\cksource\ckfinder\src\CKSource\CKFinder\CommandResolver.php(150): CKSource\CKFinder\Command\CommandAbstract->checkPermissions() 
#7 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\vendor\symfony\http-kernel\Symfony\Component\HttpKernel\HttpKernel.php(133): CKSource\CKFinder\CommandResolver->getController(Object(Symfony\Component\HttpFoundation\Request)) 
#8 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\vendor\symfony\http-kernel\Symfony\Component\HttpKernel\HttpKernel.php(66): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) 
#9 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\vendor\cksource\ckfinder\src\CKSource\CKFinder\CKFinder.php(491): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#10 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\vendor\cksource\ckfinder\src\CKSource\CKFinder\CKFinder.php(261): CKSource\CKFinder\CKFinder->handle(Object(Symfony\Component\HttpFoundation\Request)) 
#11 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\connector.php(20): CKSource\CKFinder\CKFinder->run() 
#12 {main} [] []

The URL I'm using to access CKFinder is http://*SNIP*/resources/other/ckfinder/ckfinder.html?type=Images, so the resource type is definitely set as required. It also definitely exists in the configuration as shown below.

This is the exception logged when trying to use the Quick Upload facilities:

[2015-10-19 23:06:19] CKFinder.ERROR: exception 'CKSource\CKFinder\Exception\UnauthorizedException' with message 'Unauthorized' in C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\vendor\cksource\ckfinder\src\CKSource\CKFinder\Command\CommandAbstract.php:75
Stack trace: 
#0 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\vendor\cksource\ckfinder\src\CKSource\CKFinder\CommandResolver.php(150): CKSource\CKFinder\Command\CommandAbstract->checkPermissions() 
#1 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\vendor\symfony\http-kernel\Symfony\Component\HttpKernel\HttpKernel.php(133): CKSource\CKFinder\CommandResolver->getController(Object(Symfony\Component\HttpFoundation\Request)) 
#2 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\vendor\symfony\http-kernel\Symfony\Component\HttpKernel\HttpKernel.php(66): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) 
#3 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\vendor\cksource\ckfinder\src\CKSource\CKFinder\CKFinder.php(491): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#4 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\vendor\cksource\ckfinder\src\CKSource\CKFinder\CKFinder.php(261): CKSource\CKFinder\CKFinder->handle(Object(Symfony\Component\HttpFoundation\Request)) 
#5 C:\inetpub\wwwroot\*SNIP*\resources\other\ckfinder\core\connector\php\connector.php(20): CKSource\CKFinder\CKFinder->run() 
#6 {main} [] []

And some selected relevant portions of config.php (NB. $_SESSION['guid'] is set earlier and is not the cause of the problem):

...

$config['authentication'] = function() {
    if (isset($_SESSION['guid'])) {
        return true;
    } else {
        return false;
    }
};

...

$config['backends'][] = array(
    'name'         => 'default',
    'adapter'      => 'local',
    'baseUrl'      => '/resources/uploads/'.$_SESSION['guid'].'/',
    //  'root'         => '', // Can be used to explicitly set the CKFinder user files directory.
    'chmodFiles'   => 0777,
    'chmodFolders' => 0755,
    'filesystemEncoding' => 'UTF-8',
);

...

$config['defaultResourceTypes'] = '';

$config['resourceTypes'][] = array(
    'name'              => 'Files', // Single quotes not allowed.
    'directory'         => 'files',
    'maxSize'           => 0,
    'allowedExtensions' => 'doc,docx,gif,jpeg,jpg,pdf,png,ppt,pptx,xls,xlsx',
    'deniedExtensions'  => '',
    'backend'           => 'default'
);

$config['resourceTypes'][] = array(
    'name'              => 'Images',
    'directory'         => 'images',
    'maxSize'           => 0,
    'allowedExtensions' => 'gif,jpeg,jpg,png',
    'deniedExtensions'  => '',
    'backend'           => 'default'
);

...

$config['accessControl'][] = array(
    'role'                => '*',
    'resourceType'        => '*',
    'folder'              => '/',

    'FOLDER_VIEW'         => true,
    'FOLDER_CREATE'       => true,
    'FOLDER_RENAME'       => true,
    'FOLDER_DELETE'       => true,

    'FILE_VIEW'           => true,
    'FILE_UPLOAD'         => true,
    'FILE_RENAME'         => true,
    'FILE_DELETE'         => true,

    'IMAGE_RESIZE'        => true,
    'IMAGE_RESIZE_CUSTOM' => true
);
...

Paths are set correctly and have the correct permissions. CKFinder successfully creates the '' folder as well as the .ckfinder subfolder. If using the quick upload facility, it also creates the 'image' or 'files' subfolder but doesn't upload anything.

The quick upload facilities show the 'unauthorized' exception even when I explicitly set $config['authentication'] = true;.

Other relevant information:

I've been racking my brain on this and trying to trace it for the last couple of weeks, so any assistance would be appreciated.

Upvotes: 4

Views: 5148

Answers (1)

Matt Raines
Matt Raines

Reputation: 4218

I found that explicitly listing the default resource types in config.php fixed this issue. I think it's a bug because the documentation says that all resource types are loaded if this field is left as an empty string, but leaving it as an empty string seems to break the initialisation process.

For example, in config.php, replace:

$config['defaultResourceTypes'] = '';

with:

$config['defaultResourceTypes'] = 'Files,Images';

Upvotes: 3

Related Questions