PHPackages                             bnine/filesbundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. bnine/filesbundle

ActiveSymfony-bundle[File &amp; Storage](/categories/file-storage)

bnine/filesbundle
=================

Symfony bundle for entity-based file browser and management.

v1.1.1(today)0145MITPHPPHP ^8.1

Since Aug 2Pushed 11mo agoCompare

[ Source](https://github.com/afornerot/bNine-FilesBundle)[ Packagist](https://packagist.org/packages/bnine/filesbundle)[ RSS](/packages/bnine-filesbundle/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (11)Versions (9)Used By (0)

bNine-FilesBundle
=================

[](#bnine-filesbundle)

A Symfony bundle to easily manage and browse files and directories associated with your application entities.
Includes secure file upload, download, browsing, directory management, and image gallery features, ready to integrate in your Symfony project.

Features
--------

[](#features)

- Entity-based file &amp; directory management
- Image gallery view with thumbnails and lightbox
- Secure file upload &amp; download (OneupUploader integration)
- Breadcrumb navigation and Bootstrap/FontAwesome ready templates
- Fine-grained access control (voter system)
- Easy integration and configuration
- Extensible and customizable for your own use-case

Requirements
------------

[](#requirements)

### PHP/Symfony Bundles

[](#phpsymfony-bundles)

- Symfony 7+
- PHP 8.1+
- [oneup/uploader-bundle](https://github.com/1up-lab/OneupUploaderBundle)
- [imagine/imagine](https://imagine.readthedocs.io/) (for gallery thumbnail generation)

### JavaScript/CSS Libraries

[](#javascriptcss-libraries)

You must include the following libraries in your project for the bundle's frontend to work correctly:

- [Dropzone.js](https://www.dropzone.dev/) (file upload UI)
- [Font Awesome Free](https://fontawesome.com/) (SVG icons)
- [Bootstrap](https://getbootstrap.com/) (UI framework)
- [jQuery](https://jquery.com/) (required for some interactive features)
- [GLightbox](https://biati-digital.github.io/glightbox/) (image lightbox, required for gallery view)

Example with Symfony Webpack Encore:

```
// app.js
import 'bootstrap';
import '@fortawesome/fontawesome-free';
import 'dropzone';
import 'dropzone/dist/dropzone-bootstrap.css';
import $ from 'jquery';
```

Or include via CDN in your base template:

```

```

Installation
------------

[](#installation)

```
composer require afornerot/bnine-filesbundle
```

Bundle Setup
------------

[](#bundle-setup)

### 1. Enable the Bundle

[](#1-enable-the-bundle)

If you use Symfony Flex, the bundle is auto-registered.
Otherwise, add to `config/bundles.php`:

```
return [
    // ...
    Bnine\FilesBundle\BnineFilesBundle::class => ['all' => true],
];
```

### 2. Configure Routing

[](#2-configure-routing)

Import the bundle routes in `config/routes.yaml`:

```
bninefilesbundle:
    resource: '@BnineFilesBundle/config/routes.yaml'
    prefix: '/bninefiles'
```

### 3. Configure Twig (Optional)

[](#3-configure-twig-optional)

If you want to use the provided Twig extensions or templates, add in `config/packages/twig.yaml`:

```
twig:
    paths:
        '%kernel.project_dir%/vendor/bnine/filesbundle/templates': bNineFiles
```

### 4. Configure File Uploads (OneupUploaderBundle)

[](#4-configure-file-uploads-oneupuploaderbundle)

You need to install and configure [OneupUploaderBundle](https://github.com/1up-lab/OneupUploaderBundle):

```
composer require oneup/uploader-bundle
```

The upload directory **must always be** `%kernel.project_dir%/uploads`.
Changing the upload path is **not supported**.

Example in `config/packages/oneup_uploader.yaml`:

```
oneup_uploader:
    mappings:
        bninefile:
            frontend: dropzone
```

Usage
-----

[](#usage)

### Controller Example: Initializing a File Container

[](#controller-example-initializing-a-file-container)

When creating a new entity, you should initialize the file container for the domain and entity ID after persisting the entity.
This makes the file area ready for uploads and management.

```
use Bnine\FilesBundle\Service\FileService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

#[Route('/admin/project/submit', name: 'app_admin_project_submit')]
public function submit(Request $request, EntityManagerInterface $em, FileService $fileService): Response
{
    $project = new Project();
     $form = $this->createForm(ProjectType::class, $project);
    $form->handleRequest($request);

    if ($form->isSubmitted() && $form->isValid()) {
        $em->persist($project);
        $em->flush();

        // Initialize the file container for this project
        $fileService->init('project', $project->getId());

        return $this->redirectToRoute('app_admin_project');
    }

    return $this->render('project/edit.html.twig', [
        'form' => $form,
    ]);
}}
```

### Template Integration

[](#template-integration)

To display the file container for a specific domain and entity, insert the following line in your Twig template:

```
{{ render(path("bninefiles_files", {domain: 'project', id: project.id, editable: 0})) }}
```

- **editable**: 0 renders the file browser in read-only mode.
- **editable**: 1 renders with upload, create folder, and delete options enabled.
- **compact**: Add `compact: 1` to remove the card wrapper and render just the content.

**Examples:**

```
{# Read-only file browser #}
{{ render(path("bninefiles_files", {domain: 'project', id: project.id, editable: 0})) }}

{# Editable file browser (allows upload, create folder, delete) #}
{{ render(path("bninefiles_files", {domain: 'project', id: project.id, editable: 1})) }}

{# Compact mode (no card wrapper) #}
{{ render(path("bninefiles_files", {domain: 'project', id: project.id, editable: 1, compact: 1})) }}
```

### Image Gallery

[](#image-gallery)

The bundle provides a gallery view for image files with thumbnails and lightbox support.

**Routes:**

RouteMethodDescription`bninefiles_files_gallery`GETGallery grid view (images + directories)`bninefiles_files_image`GETServes an image inline with proper Content-Type`bninefiles_files_thumbnail`GETGenerates and caches thumbnails (300px wide)**Usage:**

```
{# Gallery view (read-only) #}
{{ render(path("bninefiles_files_gallery", {domain: 'project', id: project.id, editable: 0})) }}

{# Gallery view (editable) #}
{{ render(path("bninefiles_files_gallery", {domain: 'project', id: project.id, editable: 1})) }}

{# Compact gallery (no card wrapper) #}
{{ render(path("bninefiles_files_gallery", {domain: 'project', id: project.id, editable: 1, compact: 1})) }}
```

**Features:**

- Grid layout with auto-fill columns (min 200px)
- Server-side thumbnails (300px wide, proportional height) cached in `_thumbs/300xN/`
- GLightbox integration for full-size image viewing
- Upload restricted to image files (client-side filter)
- Non-image files listed separately below the gallery grid

**Thumbnail generation:**

- Uses Imagine library for server-side thumbnail creation
- Thumbnails cached in `uploads/{domain}/{id}/_thumbs/300xN/`
- Quality: 85%, EXIF data stripped
- Fallback to original image on generation failure

Security &amp; Voters
---------------------

[](#security--voters)

The bundle provides an abstract voter.
**You must implement your own voter** in your application for fine-grained access control.

Example:

```
