PHP code example of mwguerra / filemanager

1. Go to this page and download the library: Download mwguerra/filemanager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mwguerra / filemanager example snippets


use MWGuerra\FileManager\FileManagerPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            FileManagerPlugin::make(),
        ]);
}

use MWGuerra\FileManager\FileManagerPlugin;
use MWGuerra\FileManager\Filament\Pages\FileManager;
use MWGuerra\FileManager\Filament\Pages\FileSystem;
use MWGuerra\FileManager\Filament\Pages\SchemaExample;
use MWGuerra\FileManager\Filament\Resources\FileSystemItemResource;

// Register all enabled components (default)
FileManagerPlugin::make()

// Register only specific components
FileManagerPlugin::make([
    FileManager::class,              // Database mode - full CRUD file manager
    FileSystem::class,               // Storage mode - read-only file browser
    FileSystemItemResource::class,   // Resource for direct database table editing
    SchemaExample::class,            // Demo page showing embed components usage
])

// Using the fluent API
FileManagerPlugin::make()
    ->only([
        FileManager::class,
        FileSystem::class,
    ])

use MWGuerra\FileManager\Schemas\Components\FileManagerEmbed;
use MWGuerra\FileManager\Schemas\Components\FileSystemEmbed;

// Database mode (full CRUD)
FileManagerEmbed::make()
    ->height('400px')
    ->disk('s3')
    ->target('uploads'),

// Storage mode (read-only browser)
FileSystemEmbed::make()
    ->height('400px')
    ->disk('public')
    ->target('media'),

use MWGuerra\FileManager\Schemas\Components\FileManagerEmbed;
use MWGuerra\FileManager\Schemas\Components\FileSystemEmbed;

FileManagerEmbed::make()
    // Layout options
    ->height('500px')
    ->defaultViewMode('grid')  // 'grid' or 'list'

    // Storage options
    ->disk('s3')
    ->target('uploads')
    ->initialFolder('documents')

    // Sidebar configuration
    ->showSidebar()  // or ->hideSidebar()
    ->sidebarRootLabel('My Files')
    ->sidebarHeading('Folders')
    // Or use the combined method:
    ->sidebar(show: true, rootLabel: 'My Files', heading: 'Folders')

    // Breadcrumbs configuration
    ->breadcrumbsRootLabel('Home')

    // Header configuration
    ->showHeader()  // or ->hideHeader()

    // Compact mode (no header, no sidebar)
    ->compact(),

// All options also work with FileSystemEmbed
FileSystemEmbed::make()
    ->height('400px')
    ->disk('public')
    ->sidebarRootLabel('Storage')
    ->breadcrumbsRootLabel('Root')
    ->hideSidebar(),

FileManagerEmbed::make()
    ->sidebarRootLabel(fn () => auth()->user()->name . "'s Files")
    ->breadcrumbsRootLabel(fn () => __('file-manager.home')),

use Filament\View\PanelsRenderHook;

FileManagerPlugin::make()
    // Enable panel sidebar (appears in Filament navigation)
    ->panelSidebar()
    ->panelSidebarRootLabel('My Files')
    ->panelSidebarHeading('Folders')

    // Or use the short alias
    ->sidebar()

    // Customize render hook location
    ->panelSidebar(
        enabled: true,
        renderHook: PanelsRenderHook::SIDEBAR_NAV_END,
        scopes: ['admin']
    )

    // Disable panel sidebar
    ->withoutPanelSidebar()

FileManagerPlugin::make()
    // Enable/disable the page
    ->fileManager(true)
    ->withoutFileManager()  // Disable

    // Configure page sidebar (folder tree on the page itself)
    ->fileManagerPageSidebar(true)
    ->fileManagerSidebarRootLabel('Root')
    ->fileManagerSidebarHeading('Folders')

    // Configure navigation
    ->fileManagerNavigation(
        icon: 'heroicon-o-folder',
        label: 'File Manager',
        sort: 1,
        group: 'Content'
    )

FileManagerPlugin::make()
    // Enable/disable the page
    ->fileSystem(true)
    ->withoutFileSystem()  // Disable

    // Configure page sidebar
    ->fileSystemPageSidebar(true)
    ->fileSystemSidebarRootLabel('Root')
    ->fileSystemSidebarHeading('Storage')

    // Configure navigation
    ->fileSystemNavigation(
        icon: 'heroicon-o-server-stack',
        label: 'File System',
        sort: 2,
        group: 'Content'
    )

FileManagerPlugin::make()
    ->schemaExample(true)
    ->withoutSchemaExample()  // Disable

use MWGuerra\FileManager\FileManagerPlugin;
use Filament\View\PanelsRenderHook;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            FileManagerPlugin::make()
                // Panel sidebar (in Filament navigation)
                ->panelSidebar()
                ->panelSidebarRootLabel('All Files')
                ->panelSidebarHeading('Folders')

                // File Manager page (database mode)
                ->fileManager()
                ->fileManagerPageSidebar(true)
                ->fileManagerSidebarRootLabel('Root')
                ->fileManagerSidebarHeading('Folders')
                ->fileManagerNavigation(
                    icon: 'heroicon-o-folder',
                    label: 'Files',
                    sort: 1,
                    group: 'Content'
                )

                // File System page (storage mode, read-only)
                ->fileSystem()
                ->fileSystemPageSidebar(true)
                ->fileSystemSidebarRootLabel('Storage Root')
                ->fileSystemSidebarHeading('Directories')
                ->fileSystemNavigation(
                    icon: 'heroicon-o-server-stack',
                    label: 'Storage',
                    sort: 2,
                    group: 'Content'
                )

                // Disable demo page
                ->withoutSchemaExample(),
        ]);
}

FileManagerPlugin::make()
    ->panelSidebarRootLabel('Root')  // Default for all sidebars
    ->fileManagerSidebarRootLabel('Files Root')  // Override for File Manager only

use MWGuerra\FileManager\FileManagerPlugin;
use MWGuerra\FileManager\Enums\FileManagerIcon;

FileManagerPlugin::make()
    // Override multiple icons at once
    ->icons([
        'folder' => 'phosphor-folder',  // Use a different icon set
        'document' => '<svg xmlns="http://www.w3.org/2000/svg" ...>...</svg>',  // Raw SVG
    ])

    // Or override a single icon
    ->icon(FileManagerIcon::Folder, 'tabler-folder')
    ->icon('trash', 'heroicon-s-trash')  // String keys also work

FileManagerPlugin::make()
    ->noIcons()  // Icons will not render (returns empty string)

FileManagerPlugin::make()
    ->withIcons()  // Explicitly enable (default)

use MWGuerra\FileManager\Enums\FileManagerIcon;

// In Blade templates
{!! FileManagerIcon::Folder->render('w-5 h-5 text-primary-500') !!}

// Using the helper function
{!! fmicon('folder', 'w-5 h-5') !!}
{!! fmicon(FileManagerIcon::Document, 'w-4 h-4 text-gray-500') !!}
bash
php artisan vendor:publish --tag=filemanager-config
bash
php artisan migrate
bash
php artisan filemanager:install
bash
php artisan filemanager:install [options]
bash
php artisan filemanager:rebuild [options]
bash
php artisan filemanager:upload <path> [options]