Skip to content

Anfallnorr/FileManagerSystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FileManagerSystem

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.

🚀 Installation

Install the bundle via Composer:

composer require anfallnorr/file-manager-system

⚙️ Configuration

1. Register the Bundle

Add the bundle to your config/bundles.php file:

return [
    // ...
    Anfallnorr\FileManagerSystem\FileManagerSystem::class => ['all' => true],
];

2. AssetMapper Configuration (Optional)

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 

💡 Usage

Injecting the Service

public function __construct(
    private FileManagerService $fmService
) {
    $this->fmService
        ->setDefaultDirectory('/var/uploads')
        ->setRelativeDirectory('/var/uploads');
}
$fmService = $this->fmService;

📚 Examples

Get the default upload directory

$defaultDirectory = $fmService->getDefaultDirectory();
// e.g. /path/to/project/public/uploads

Change the default upload directory

$directory = $fmService
	->setDefaultDirectory(directory: '/var/www/uploads')
	->getDefaultDirectory();
// e.g. /path/to/project/var/www/uploads

Retrieve all available MIME types

$mimeTypes = $fmService->getMimeTypes();
// returns an array

Get the MIME type for a specific extension

$mimeType = $fmService->getMimeType(key: 'pdf');
// application/pdf

Create a URL-friendly slug

$slug = $fmService->createSlug(string: 'Hello World !');
// hello-world

Create a directory

$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
]

Create a file with optional content

$fmService->createFile(
	filename: 'Hello World.html',
	content: 'Hello World! I\'m Js Info'
);

🧩 Optional (Twig Integration)

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']