ckfinder / ckfinder-laravel-package

CKFinder 3 package for Laravel
Other
153 stars 86 forks source link

How could create private folders per user with CKEditor ? #71

Closed hoantv1107 closed 1 year ago

hoantv1107 commented 2 years ago

I try to add baseurl with custom url in config.php

$config['backends']['default'] = array( 'name' => 'default', 'adapter' => 'local', 'baseUrl' => config('app.url').'/userfiles/.$user_id', 'root' => public_path('/userfiles/'.$user_id), 'chmodFiles' => 0777, 'chmodFolders' => 0755, 'filesystemEncoding' => 'UTF-8' );

but it not work.

presleyd commented 2 years ago

I don't believe you can do this in the config.php but you CAN do it via the middleware (app/Http/Middleware/CKFinder.php)

Set the default backend to the base folder that holds all the user folders.

config.php

...

$config['backends']['default'] = array(
'name' => 'default',
'adapter' => 'local',
'baseUrl' => config('app.url') . '/userfiles/',
'root' => public_path('/userfiles/'),
'chmodFiles' => 0777,
'chmodFolders' => 0755,
'filesystemEncoding' => 'UTF-8'
);

Add a resource for the user folder and set the access control for it.

app/Http/Middleware/CKFinder.php

$resources[] = [
    'name' => $user_id,
    'directory' => $user_id,
    'maxSize' => 0,
    'allowedExtensions' => '<whatever you want>',
    'deniedExtensions'  => '',
    'backend'           => 'default'
];

...

$accessControl[] = [
    'role'                => '*',
    'resourceType'        => $user_id,
    '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
];