1. Go to this page and download the library: Download krma-cl/kcfinder-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
krma-cl / kcfinder-laravel example snippets
use Illuminate\Support\Facades\Gate;
Gate::define('kcfinder.select', static function ($user, string $operation, string $path): bool {
return $user->can('manage-files');
});
use Krma\KCFinder\Laravel\Contracts\PreviewUrlResolverInterface;
use Krma\KCFinder\Laravel\Contracts\SelectedUrlResolverInterface;
$this->app->bind(PreviewUrlResolverInterface::class, AuthenticatedPreviewResolver::class);
$this->app->bind(SelectedUrlResolverInterface::class, PublicAssetResolver::class);
use Krma\KCFinder\Laravel\Facades\KCFinder;
$result = KCFinder::reportUploaded('/images/photo.jpg');
return response()->json($result, $result->httpStatus());
use Krma\KCFinder\Laravel\Domain\OperationResult;
$result = OperationResult::failure(
'upload',
'MIME_NOT_ALLOWED',
'The detected file type is not allowed.',
415
);
use Krma\KCFinder\Laravel\Domain\OperationWarning;
$result = KCFinder::reportUploaded('/images/photo.jpg', [
new OperationWarning(
'CATALOG_SYNC_FAILED',
'The file was saved, but catalog synchronization must be retried.'
),
]);
use KCFinder\Contract\OperationObserverInterface;
$_LOCALS['_operationObserver'] = app(OperationObserverInterface::class);
use Krma\KCFinder\Laravel\Events\FileMoved;
final class SynchronizeCatalog
{
public function handle(FileMoved $event): void
{
$oldPath = $event->previous->file->path;
$newPath = $event->file->path;
$checksum = $event->file->checksum;
$user = $event->user;
}
}
$before = KCFinder::snapshot('/images/old-name.jpg', 'rename');
// Perform the authorized rename in the existing KCFinder integration.
$result = KCFinder::reportRenamed($before, '/images/new-name.jpg');
return response()->json($result, $result->httpStatus());