FileManagerSystem is a Symfony bundle that provides easy and intuitive management of files and directories: creation, deletion, moving, MIME type handling, image resizing, and more.
It is designed to simplify file management within any Symfony application.
Install the bundle via Composer:
composer require anfallnorr/file-manager-systemAdd the bundle to your config/bundles.php file:
return [
// ...
Anfallnorr\FileManagerSystem\FileManagerSystem::class => ['all' => true],
];If you want to use the built-in controller and assets provided by the bundle, create the following configuration files.
Create config/packages/file_manager_system.yaml
framework:
asset_mapper:
paths:
- '%kernel.project_dir%/vendor/anfallnorr/file-manager-system/assets'Create config/routes/file_manager_system.yaml
file_manager_system:
resource: '../../vendor/anfallnorr/file-manager-system/src/Controller/'
type: attribute
prefix: /files-manager public function __construct(
private FileManagerService $fmService
) {
$this->fmService
->setDefaultDirectory('/var/uploads')
->setRelativeDirectory('/var/uploads');
}$fmService = $this->fmService;$defaultDirectory = $fmService->getDefaultDirectory();
// e.g. /path/to/project/public/uploads$directory = $fmService
->setDefaultDirectory(directory: '/var/www/uploads')
->getDefaultDirectory();
// e.g. /path/to/project/var/www/uploads$mimeTypes = $fmService->getMimeTypes();
// returns an array$mimeType = $fmService->getMimeType(key: 'pdf');
// application/pdf$slug = $fmService->createSlug(string: 'Hello World !');
// hello-world$fmService->createDir(directory: 'Hello World !', return: false);If return is set to true, the method returns:
[
'absolute' => "/absolute/path/hello-world",
'relative' => $relative,
'ltrimmed_relative' => \ltrim($relative, '/'),
'foldername' => $dir
]$fmService->createFile(
filename: 'Hello World.html',
content: 'Hello World! I\'m Js Info'
);If you are using Twig and want Bootstrap-styled forms, add this in:
config/packages/twig.yaml
twig:
form_themes: ['bootstrap_5_layout.html.twig']