anfallnorr / file-manager-system
A Symfony bundle for file management (move, copy, delete, resize, etc.).
Installs: 37
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.3
- symfony/asset: 7.2.*
- symfony/flex: ^2.4.7
- symfony/form: 7.2.*
- symfony/framework-bundle: 7.2.*
- symfony/http-foundation: ^7.2
- symfony/mime: 7.2.*
- symfony/string: 7.2.*
- symfony/translation: 7.2.*
- symfony/twig-bundle: 7.2.*
- symfony/validator: 7.2.*
README
FileManagerSystem is a Symfony bundle to easily manage files and directories: creation, deletion, moving, resizing images, managing MIME types, etc.
Installation
Install FileManagerSystem via Composer
composer require anfallnorr/file-manager-system
Configuration
Add to /config/bundles.php
Register the bundle in config/bundles.php
# config/bundles.php return [ ... Anfallnorr\FileManagerSystem\FileManagerSystem::class => ['all' => true], ];
Usage
Initialize in a Controller
public function __construct( private FileManagerService $fmService ) { $fmService ->setDefaultDirectory('/var/uploads') ->setRelativeDirectory('/var/uploads'); }
$fmService = $this->fmService;
Examples
// Get the default upload directory path $defaultDirectory = $fmService->getDefaultDirectory(); // /path/to/folder/public/uploads // Change the default upload directory $directory = $fmService->setDefaultDirectory($directory = '/var/www/uploads')->getDefaultDirectory(); // /path/to/folder/var/www/uploads // Retrieve available MIME types $mimeTypes = $fmService->getMimeTypes(); // array // Get the MIME type of a specific extension $mimeType = $fmService->getMimeType($key = 'pdf'); // application/pdf // Create a URL-friendly slug from a string $string = $fmService->createSlug($string = 'Hello World !'); // hello-world // Create a directory named "hello-world" inside the default directory $fmService->createDir($directory = 'Hello World !', $return = false); // if $return is `true`, then an array will be returned: [ 'absolute' => $this->getDefaultDirectory() . '/hello-world', // Absolute path 'relative' => $relative, // Relative path of the folder 'ltrimed_relative' => ltrim($relative, '/'), // Relative path of the folder minus a slash at the beginning of the string 'foldername' => $dir // The name of the folder created ] // Create a file named "hello-world.html" inside the default directory with content $fmService->createFile($filename = 'Hello World.html', $content = 'Hello World! I\'m Js info'); // $content is optional
Optional Configuration
If you are using Twig, add Bootstrap form themes in config/packages/twig.yaml
# app/config/packages/twig.yaml twig: form_themes: ['bootstrap_5_layout.html.twig']