Cài đặt Filemanager trong Laravel 5

Hướng dẫn cài đặt laravel filemanager và tích hợp laravel-filemanager vào ckeditor.

1. Yêu cầu hệ thống:

  • Phiên bản php >= 5.4
  • Laravel 5
  • Cài đặt intervention/image

2. Cài đặt:

Cài đặt package: Sử dụng composer

    $ composer require unisharp/laravel-filemanager

Cấu hình file config/app.php

  • Thêm vào providers dòng:
                 Unisharp\Laravelfilemanager\LaravelFilemanagerServiceProvider::class,
                 Intervention\Image\ImageServiceProvider::class,
            
  • Thêm vào aliases dòng:
                 'Image' => Intervention\Image\Facades\Image::class,
            

Copy thư mục, file cần thiết ra thư mục public và config

     php artisan vendor:publish --tag=lfm_config
     php artisan vendor:publish --tag=lfm_public

Sử dụng:

Chèn đoạn code này vào view bạn muốn hiển thị:

	
    
    

    
    

Cấu hình file config/lfm.php

    /*
|--------------------------------------------------------------------------
| Routing
|--------------------------------------------------------------------------
*/

// Include to pre-defined routes from package or not. Middlewares
'use_package_routes' => true,

// Middlewares which should be applied to all package routes.
// For laravel 5.1 and before, remove 'web' from the array.
'middlewares' => ['web','auth'],

// The url to this package. Change it if necessary.
'prefix' => 'laravel-filemanager',

/*
|--------------------------------------------------------------------------
| Multi-User Mode
|--------------------------------------------------------------------------
*/

// If true, private folders will be created for each signed-in user.
'allow_multi_user' => true,

// The database column to identify a user. Make sure the value is unique.
// Ex: When set to 'id', the private folder of user will be named as the user id.
'user_field' => 'id',

/*
|--------------------------------------------------------------------------
| Working Directory
|--------------------------------------------------------------------------
*/

// Which folder to store files in project, fill in 'public', 'resources', 'storage' and so on.
// You should create routes to serve images if it is not set to public.
'base_directory' => 'public',

'images_folder_name' => 'photos',
'files_folder_name'  => 'files',

'shared_folder_name' => 'shares',
'thumb_folder_name'  => 'thumbs',

/*
|--------------------------------------------------------------------------
| Startup Views
|--------------------------------------------------------------------------
*/

// The default display type for items.
// Supported: "grid", "list"
'images_startup_view' => 'grid',
'files_startup_view' => 'list',

/*
|--------------------------------------------------------------------------
| Upload / Validation
|--------------------------------------------------------------------------
*/

// If true, the uploaded file will be renamed to uniqid() + file extension.
'rename_file' => false,

// If rename_file set to false and this set to true, then non-alphanumeric characters in filename will be replaced.
'alphanumeric_filename' => true,

// If true, non-alphanumeric folder name will be rejected.
'alphanumeric_directory' => false,

'max_image_size' => 500,
'max_file_size' => 1000,

// available since v1.3.0
'valid_image_mimetypes' => [
    'image/jpeg',
    'image/pjpeg',
    'image/png',
    'image/gif'
],

// available since v1.3.0
// only when '/laravel-filemanager?type=Files'
'valid_file_mimetypes' => [
    'image/jpeg',
    'image/pjpeg',
    'image/png',
    'image/gif',
    'application/pdf',
    'text/plain',
],

/*
|--------------------------------------------------------------------------
| File Extension Information
|--------------------------------------------------------------------------
*/

'file_type_array' => [
    'pdf'  => 'Adobe Acrobat',
    'doc'  => 'Microsoft Word',
    'docx' => 'Microsoft Word',
    'xls'  => 'Microsoft Excel',
    'xlsx' => 'Microsoft Excel',
    'zip'  => 'Archive',
    'gif'  => 'GIF Image',
    'jpg'  => 'JPEG Image',
    'jpeg' => 'JPEG Image',
    'png'  => 'PNG Image',
    'ppt'  => 'Microsoft PowerPoint',
    'pptx' => 'Microsoft PowerPoint',
],

'file_icon_array' => [
    'pdf'  => 'fa-file-pdf-o',
    'doc'  => 'fa-file-word-o',
    'docx' => 'fa-file-word-o',
    'xls'  => 'fa-file-excel-o',
    'xlsx' => 'fa-file-excel-o',
    'zip'  => 'fa-file-archive-o',
    'gif'  => 'fa-file-image-o',
    'jpg'  => 'fa-file-image-o',
    'jpeg' => 'fa-file-image-o',
    'png'  => 'fa-file-image-o',
    'ppt'  => 'fa-file-powerpoint-o',
    'pptx' => 'fa-file-powerpoint-o',
],

Lưu ý: middlewaresuser_field cấu hình theo mục đích sử dụng của bạn nhé.

Kết quả: