bnine/filesbundle
Symfony 7+ bundle to manage files and directories linked to your entities. Provides secure upload/download (OneupUploader), browsing with breadcrumbs, Bootstrap/FontAwesome templates, directory management, and voter-based access control.
Install Dependencies
composer require afornerot/bnine-filesbundle oneup/uploader-bundle
Configure Required Libraries
Add to your app.js (Webpack Encore) or include via CDN in your base template:
<!-- CDN Example -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dropzone@6/dist/dropzone.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dropzone-bootstrap@1/dist/dropzone-bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dropzone@6/dist/dropzone.min.js"></script>
Enable the Bundle
Add to config/bundles.php (if not using Symfony Flex):
Bnine\FilesBundle\BnineFilesBundle::class => ['all' => true],
Configure Routing
Add to config/routes.yaml:
bninefilesbundle:
resource: '@BnineFilesBundle/config/routes.yaml'
prefix: '/bninefiles'
Configure OneupUploader
Add to config/packages/oneup_uploader.yaml:
oneup_uploader:
mappings:
bninefile:
frontend: dropzone
Initialize File Container In your controller, initialize the file container after persisting an entity:
$fileService->init('project', $project->getId());
Display File Browser in Template Insert the Twig snippet where needed:
{{ render(path("bninefiles_files", {domain: 'project', id: project.id, editable: 1})) }}
Entity-Based File Management
FileService to initialize a file container for any entity after saving it to the database.init('project', $projectId) creates a directory structure for a project.Secure File Uploads
OneupUploaderBundle for handling file uploads.editable: 1 parameter in Twig to enable uploads via Dropzone.js.Access Control
FileVoter to define permissions for viewing, editing, and deleting files.Template Integration
render Twig function to embed the file browser in any template.editable parameter to switch between read-only and full-featured modes.Breadcrumbs and Navigation
templates/bNineFiles/ directory.FileVoter as a base for custom security logic.FileService methods to manage files programmatically (e.g., delete all files for a project).Fixed Upload Path
%kernel.project_dir%/uploads. Changing this will break the bundle.Missing Dependencies
Security Misconfigurations
FileVoter, all users will have full access to files.canView, canEdit, and canDelete methods in your voter.Template Overrides
files/index.html.twig).Entity Initialization
init() on an entity will result in a missing directory.config/routes.yaml.FileVoter is properly registered and configured.Custom File Types
FileService to support additional file operations (e.g., file previews, metadata extraction).Advanced Voters
FileVoter for domain-specific permissions (e.g., role-based access).Event Listeners
files.post_upload or files.post_delete events for post-processing.API Integration
FileService methods in API controllers to manage files via endpoints.frontend: dropzone mapping is correctly set in oneup_uploader.yaml.twig.yaml.FileService::deleteAll() to clean up files for deleted entities.How can I help you explore Laravel packages today?