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.0.6(9mo ago)091MITPHPPHP ^8.1

Since Aug 2Pushed 9mo agoCompare

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

READMEChangelogDependencies (2)Versions (6)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, and directory management features, ready to integrate in your Symfony project.

Features
--------

[](#features)

- Entity-based file &amp; directory management
- Secure file upload &amp; download (OneupUploader integration)
- Breadcumb 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)

### 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)

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.

**Example:**

```
{# 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})) }}
```

This is the only integration you need in your templates.
Just insert this line wherever you want the file manager to appear!

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:

```
