Installation:
composer require helios-ag/fm-elfinder-bundle
bin/console elfinder:install
This copies ElFinder assets to public/ and sets up basic routing.
Routing:
Add to config/routes.yaml:
elfinder:
resource: "@FMElfinderBundle/Resources/config/routing.yaml"
Security:
Secure routes in config/security.yaml:
access_control:
- { path: ^/efconnect, role: ROLE_USER }
- { path: ^/elfinder, role: ROLE_USER }
Basic Config:
Define a root directory in config/packages/fm_elfinder.yaml:
fm_elfinder:
instances:
default:
connector:
roots:
uploads:
driver: LocalFileSystem
path: "%kernel.project_dir%/public/uploads"
upload_allow: ['image/png', 'image/jpg']
upload_deny: ['all']
First Use Case: Integrate with a WYSIWYG editor (e.g., CKEditor) by referencing the ElFinder instance in your editor config:
CKEDITOR.replace('editor', {
filebrowserBrowseUrl: '/elfinder/ckeditor',
filebrowserUploadUrl: '/elfinder/ckeditor/upload'
});
File Management Integration:
fm_elfinder form type for Symfony forms:
use FM\ElfinderBundle\Form\Type\ElfinderType;
$builder->add('image', ElfinderType::class, [
'instance' => 'default',
'multiple' => true,
]);
# config/packages/easy_admin.yaml
easy_admin:
form_types:
- FM\ElfinderBundle\Form\Type\ElfinderType
Multi-User File Isolation:
fm_elfinder:
instances:
user_files:
where_is_multi:
roots: 0
multi_home_folder: true
folder_separator: "|"
connector:
roots:
uploads:
driver: LocalFileSystem
path: "%kernel.project_dir%/public/uploads"
/elfinder/user_files/{username}.Editor-Specific Configurations:
fm_elfinder:
instances:
ckeditor:
editor: ckeditor
connector:
roots:
uploads:
driver: LocalFileSystem
path: "uploads"
fm_elfinder:
instances:
tinymce:
editor: fm_tinymce
connector:
roots:
uploads:
driver: LocalFileSystem
path: "uploads"
Custom Templates:
custom editor:
fm_elfinder:
instances:
custom_editor:
editor: custom
editor_template: "FMElfinderBundle:Elfinder:custom.html.twig"
Event-Driven Extensions:
// src/EventListener/ElFinderListener.php
use FM\ElfinderBundle\Event\ElFinderPreExecutionEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ElFinderListener implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'fm_elfinder.event.pre_execution' => 'onPreExecution',
];
}
public function onPreExecution(ElFinderPreExecutionEvent $event)
{
$request = $event->getRequest();
if ($request->query->get('cmd') === 'open') {
$event->setHomeFolder('user_'.$request->get('user_id'));
}
}
}
services.yaml:
services:
App\EventListener\ElFinderListener:
tags:
- { name: fm_elfinder.event_listener }
CORS Configuration:
cors_support in config if using cross-domain requests:
fm_elfinder:
cors_support: true
NelmioCorsBundle for cross-domain clients.File Permissions:
path in roots is writable by the web server (e.g., chmod -R 775 uploads).Driver-Specific Quirks:
public/ by default. Use absolute paths (e.g., %kernel.project_dir%/public/uploads) for clarity.Editor Integration:
filebrowserBrowseUrl and filebrowserUploadUrl with /elfinder/{instance}.file_picker_callback and file_browser_callback to point to /elfinder/{instance}.Multi-Home Folders:
multi_home_folder feature only works with LocalFileSystem. Ensure home folders (e.g., uploads/{user}) exist and are writable.Debugging:
connector:
debug: true
var/log/dev.log) for ElFinder errors.Dynamic Instance Names:
Use instance names dynamically (e.g., {user}_files) to isolate user uploads without complex routing.
MIME Type Filtering: Restrict uploads to specific MIME types for security:
upload_allow: ['image/png', 'image/jpg', 'application/pdf']
upload_deny: ['all']
Custom Attributes: Lock or restrict access to folders:
attributes:
- { pattern: '/protected/', read: true, write: false, locked: true }
Asset Paths:
Override the default asset path (/assets) if needed:
assets_path: "/custom/path"
Performance:
visible_mime_types to reduce UI clutter:
visible_mime_types: ['image/png', 'image/jpg', 'application/pdf']
Testing:
ElFinder service in PHPUnit:
$this->container->get('fm_elfinder.elfinder')->method('run')->willReturn(['output' => 'test']);
ElFinderTestCase base class if available.Backup Roots: Define multiple roots for redundancy:
roots:
primary:
driver: LocalFileSystem
path: "uploads/primary"
backup:
driver: LocalFileSystem
path: "uploads/backup"
Localization:
Override ElFinder’s language files by copying them to public/assets/elfinder/lang/ and translating keys.
Symfony Service as Driver: Use a custom service as a volume driver (advanced):
fm_elfinder:
instances:
custom_driver:
connector:
roots:
custom:
driver: "service_id"
Implement FM\ElfinderBundle\Driver\VolumeDriverInterface.
Legacy Editors:
For TinyMCE 3.x, use the tinymce editor instance:
fm_elfinder:
instances:
tinymce3:
editor: tinymce
How can I help you explore Laravel packages today?