PHP code example of ssh521 / laravel-file-manager

1. Go to this page and download the library: Download ssh521/laravel-file-manager 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/ */

    

ssh521 / laravel-file-manager example snippets


<a href="{{ route('file-manager.index') }}" class="inline-flex items-center px-4 py-2 bg-blue-600 border border-transparent rounded-lg text-sm font-medium text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 transition-colors duration-200">
    <i class="fas fa-folder-open mr-2"></i>
    Open File Manager
</a>

return [
    // Storage paths
    'storage_path' => 'app/public',
    'public_path' => 'storage',

    // Route configuration
    'route' => [
        'prefix' => 'file-manager',
        'name' => 'file-manager',
        'middleware' => ['web', 'auth'], // Add authentication
    ],

    // UI configuration
    'title' => 'File Manager',
    'root_name' => 'Storage',
    'back_route' => null, // Optional back button route
    'back_text' => '돌아가기',

    // File upload configuration
    'max_file_size' => 10240, // KB (10MB)
    'allowed_mimes' => [], // Empty = allow all file types

    // Image file extensions for preview
    'image_extensions' => ['jpg', 'jpeg', 'png', 'gif', 'svg', 'webp'],

    // Security settings
    'forbidden_extensions' => ['php', 'js', 'html', 'htm'],
    'folder_name_pattern' => '/^[a-zA-Z0-9\-_\s]+$/',

    // Feature toggles
    'features' => [
        'upload' => true,
        'create_folder' => true,
        'delete' => true,
        'rename' => false, // Not implemented yet
        'move' => false,   // Not implemented yet
    ],
];

// In your admin panel or navigation
<a href="{{ route('file-manager.index') }}" class="flex items-center px-3 py-2 text-sm font-medium text-gray-700 rounded-lg hover:bg-gray-100 hover:text-gray-900 transition-colors duration-200">
    <i class="fas fa-folder text-blue-600 mr-2"></i> File Manager
</a>

'back_route' => 'admin.dashboard',
'back_text' => 'Back to Dashboard',

'route' => [
    'middleware' => ['web'], // Basic web routes
    // or
    'middleware' => ['web', 'auth'], // Requires authentication
    // or  
    'middleware' => ['web', 'auth', 'admin'], // Requires authentication + admin role
],

'storage_path' => 'app/public',  // Laravel storage path
'public_path' => 'storage',      // Public URL path

'route' => [
    'prefix' => 'admin/files',       // Custom URL prefix
    'name' => 'admin.files',         // Route name prefix
    'middleware' => ['web', 'auth'], // Route middleware
],

'max_file_size' => 5120,  // 5MB in KB
'allowed_mimes' => [
    'image/jpeg',
    'image/png', 
    'application/pdf',
],
'forbidden_extensions' => ['php', 'exe', 'bat'],

'title' => 'My File Manager',
'root_name' => 'Files',
'back_route' => 'dashboard',
'back_text' => 'Go Back',



namespace App\Http\Controllers;

use Ssh521\LaravelFileManager\Http\Controllers\FileManagerController as BaseController;

class CustomFileManagerController extends BaseController
{
    public function index(Request $request)
    {
        // Add custom logic
        return parent::index($request);
    }
}
bash
php artisan vendor:publish --tag=file-manager-config
bash
php artisan vendor:publish --tag=file-manager-views
bash
php artisan storage:link
bash
php artisan vendor:publish --tag=file-manager-views