barryvdh/elfinder-flysystem-driver
Flysystem driver for elFinder, connecting the elFinder file manager to Laravel and other PHP apps via League\Flysystem adapters. Browse, upload, and manage files across local disks and cloud storage backends through a unified filesystem layer.
Installation
composer require barryvdh/elfinder-flysystem-driver
Ensure league/flysystem and barryvdh/laravel-elfinder are also installed (core dependencies).
Register the Driver
In config/elfinder.php, add the Flysystem driver under drivers:
'drivers' => [
'local' => [
'driver' => 'local',
],
'flysystem' => [
'driver' => 'barryvdh\ElfinderFlysystemDriver\ElfinderFlysystem',
'filesystem' => 's3', // Your Flysystem adapter name
],
],
First Use Case Configure a route to serve elFinder with the Flysystem driver:
Route::get('/elfinder', '\Barryvdh\Elfinder\Facades\Elfinder::open');
Ensure your Flysystem adapter (e.g., S3, Dropbox) is properly configured in config/filesystems.php.
Multi-Adapter Support
Use the same elFinder UI to manage files across different Flysystem adapters (e.g., local, S3, Dropbox) by defining multiple drivers in config/elfinder.php:
'drivers' => [
's3' => ['driver' => 'barryvdh\ElfinderFlysystemDriver\ElfinderFlysystem', 'filesystem' => 's3'],
'dropbox' => ['driver' => 'barryvdh\ElfinderFlysystemDriver\ElfinderFlysystem', 'filesystem' => 'dropbox'],
],
Switch adapters dynamically via JavaScript:
$('#elfinder').elfinder({
url: '/elfinder?driver=s3', // or 'dropbox'
});
Custom Permissions Override default permissions (e.g., disable uploads for read-only adapters) by extending the driver:
use Barryvdh\ElfinderFlysystemDriver\ElfinderFlysystem;
class CustomElfinderFlysystem extends ElfinderFlysystem {
public function getConfig() {
$config = parent::getConfig();
$config['disabled'] = ['upload', 'mkfile', 'mkdir']; // Disable actions
return $config;
}
}
Register the custom driver in config/elfinder.php:
'drivers' => [
'custom-s3' => [
'driver' => 'App\CustomElfinderFlysystem',
'filesystem' => 's3',
],
],
Event-Driven Integrations Listen to elFinder events (e.g., file uploads) to trigger Laravel logic:
Elfinder::event('upload', function ($event) {
$file = $event->getFile();
// Process $file->getPathname() (Flysystem path)
event(new FileUploaded($file->getPathname()));
});
Laravel Storage Integration
Use Laravel’s Storage facade to interact with files post-elFinder operations:
use Illuminate\Support\Facades\Storage;
$path = 's3:user-uploads/file.txt';
Storage::put($path, 'Content...'); // Sync with elFinder
Thumbnail Generation
For image previews, integrate with intervention/image:
Elfinder::event('init', function () {
Elfinder::driver('flysystem')->setConfig([
'thumbsMime' => ['image/jpeg', 'image/png'], // Enable thumbnails
]);
});
Caching Cache Flysystem filesystem instances to avoid reinitialization:
$filesystem = Cache::remember('flysystem.s3', 3600, function () {
return Storage::disk('s3')->getDriver();
});
Filesystem Initialization
config/filesystems.php and test with:
Storage::disk('s3')->listContents();
Permission Mismatches
AccessDenied errors if Flysystem permissions differ from expected.setVisibility() or setVisibilityCallback in the driver:
$driver->setVisibilityCallback(function ($path) {
return 'public'; // Force public visibility
});
Path Normalization
s3://bucket/path) may not work with elFinder’s local path expectations.$path = str_replace('s3://', '', $path); // Strip adapter prefix
Large File Handling
upload_max_filesize, max_execution_time) and use chunked uploads:
Elfinder::driver('flysystem')->setConfig([
'uploadMaxSize' => '100M',
'uploadChunkSize' => '5M',
]);
Enable Logging
Add debug output to config/elfinder.php:
'debug' => env('APP_DEBUG', false),
'log' => storage_path('logs/elfinder.log'),
Check Driver Output
Use dd() or Log::debug() in the driver’s methods (e.g., getChildren) to inspect Flysystem responses.
Custom Metadata Extend file metadata with Flysystem-specific data:
Elfinder::event('getFile', function ($event) {
$file = $event->getFile();
$file->set('custom', [
'size_human' => size_format($file->getSize()),
'url' => Storage::disk('s3')->url($file->getPathname()),
]);
});
Dynamic Driver Switching Switch drivers at runtime based on user roles or contexts:
$driver = auth()->user()->isAdmin() ? 's3' : 'local';
Elfinder::driver($driver)->open();
Webhook Triggers
Use Laravel’s queue to process elFinder actions asynchronously:
Elfinder::event('upload', function ($event) {
ProcessFileUpload::dispatch($event->getFile())->delay(now()->addSeconds(10));
});
How can I help you explore Laravel packages today?