nao-pon/elfinder-flysystem-driver-ext
Extended Flysystem driver for elFinder (nao-pon/elfinder), adding broader filesystem adapter support to connect elFinder’s file manager to various storage backends through Flysystem, including extra/legacy adapters beyond the core driver.
Installation
composer require nao-pon/elfinder-flysystem-driver-ext
Ensure league/flysystem and nao-pon/elfinder are also installed.
Register the Driver
In your config/elfinder.php, extend the Flysystem driver configuration:
'drivers' => [
'flysystem' => [
'adapter' => \NaoPon\ElfinderFlysystemDriverExt\FlysystemDriver::class,
'options' => [
'root' => storage_path('app'),
// Other Flysystem adapter options...
],
],
],
First Use Case Initialize elFinder with the extended driver in a controller or blade view:
use NaoPon\ElfinderFlysystemDriverExt\FlysystemDriver;
$elfinder = new \Elfinder\Elfinder([
'driver' => 'flysystem',
'root' => storage_path('app'),
'tmbPath' => storage_path('app/thumbs'),
]);
File Operations
Leverage Flysystem’s capabilities (e.g., copy, move, delete) via elFinder’s UI:
$elfinder->copy('source.txt', 'destination.txt');
$elfinder->move('old.txt', 'new.txt');
Custom Permissions
Extend file permissions logic by overriding the driver’s isAccessible() or isReadable() methods:
class CustomFlysystemDriver extends FlysystemDriver {
public function isAccessible($path) {
// Custom logic (e.g., check user roles)
return parent::isAccessible($path);
}
}
Thumbnail Generation
Use the tmbPath config to auto-generate thumbnails for images:
$elfinder->mkThumb('image.jpg', 150, 150);
Event Listeners
Hook into elFinder events (e.g., upload, delete) to sync with external systems:
$elfinder->on('upload', function ($event) {
// Sync to S3, log activity, etc.
});
Driver Class Name
Ensure the driver class (NaoPon\ElfinderFlysystemDriverExt\FlysystemDriver) is correctly referenced in config/elfinder.php. Typos here will cause silent failures.
Flysystem Adapter Compatibility
The extended driver assumes standard Flysystem adapters (e.g., Local, S3). Unsupported adapters may throw UnsupportedAdapterException.
Thumbnail Paths
If tmbPath is misconfigured, thumbnails will fail to generate. Verify the directory exists and is writable:
mkdir -p storage/app/thumbs && chmod -R 775 storage/app/thumbs
Enable Logging
Add to config/elfinder.php:
'debug' => true,
Check storage/logs/laravel.log for driver-specific errors.
Check Adapter Initialization If files disappear or operations fail, validate the Flysystem adapter is properly initialized:
$adapter = \League\Flysystem\Adapter\Local::class; // Example
$this->adapter = new $adapter($this->options['root']);
Override Driver Methods Extend the driver to add custom logic (e.g., file validation):
class CustomDriver extends FlysystemDriver {
public function upload($file, $path) {
if (!$this->isAllowedFile($file)) {
throw new \RuntimeException('File type not allowed.');
}
return parent::upload($file, $path);
}
}
Add Custom Commands
Use elFinder’s commands config to inject custom actions:
'commands' => [
'custom' => [
'exec' => 'App\Elfinder\CustomCommand',
'roles' => ['*'],
],
],
Leverage Flysystem Events
Tap into Flysystem’s events (e.g., preUpload, postDelete) for side effects:
$adapter->addListener('preUpload', function ($event) {
// Pre-process file before upload
});
How can I help you explore Laravel packages today?