# 2 laravel-filemanager

This package is functional, but is under active development.

equirements

  1. This package only supports Laravel 5.x
  2. Requires "intervention/image": "2.*"
  3. Requires PHP 5.5 or later

Installation

  1. Installation is done through composer and packagist. From within your project root directory, execute the following command:composer require tsawler/laravel-filemanager
  2. Next run composer update to install the package from packagist:composer update
  3. Add the ServiceProvider to the providers array in config/app.php:'TsawlerLaravelfilemanagerLaravelFilemanagerServiceProvider',
  4. Publish the package’s config file:php artisan vendor:publish --tag=lfm_config
  5. Publish the package’s public folder assets:php artisan vendor:publish --tag=lfm_public
  6. If you want to customize the look & feel, then publish the package’s views:php artisan vendor:publish --tag=lfm_views
  7. By default, the package will use its own routes. If you don’t want to use those routes, change this entry in config/lfm.php to false:
        'use_package_routes' => true,

    You will, of course, have to set up your own routes.

  8. If you don’t want to use the default image/file directory or url, update the appropriate lines in config/lfm.php:
        'images_dir'         => 'public/vendor/laravel-filemanager/images/',
        'images_url'         => '/vendor/laravel-filemanager/images/',
        'files_dir'          => 'public/vendor/laravel-filemanager/files/',
        'files_url'          => '/vendor/laravel-filemanager/files/',
  9. Ensure that the files & images directories are writable by your web serber
  10. In the view where you are using a CKEditor instance, use the file uploader by initializing the CKEditor instance as follows:
        <script>
            CKEDITOR.replace( 'editor', {
                filebrowserImageBrowseUrl: '/laravel-filemanager?type=Images',
                filebrowserBrowseUrl: '/laravel-filemanager?type=Files'
            });
        </script>

    Here, “editor” is the id of the textarea you are transforming to a CKEditor instance. Note that if you are using a custom route you will have to change /laravel-filemanager?type=Images to correspond to whatever route you have chosen. Be sure to include the ?type=Images parameter.

Security

It is important to note that if you use your own routes you must protect your routes to Laravel-Filemanager in order to prevent unauthorized uploads to your server. Fortunately, Laravel makes this very easy.

If, for example, you want to ensure that only logged in users have the ability to access the Laravel-Filemanager, simply wrap the routes in a group, perhaps like this:

Route::group(array('before' => 'auth'), function ()
{
    Route::get('/laravel-filemanager', 'Tsaw[email protected]');
    Route::post('/laravel-filemanager/upload', '[email protected]');
    // list all lfm routes here...
});

This approach ensures that only authenticated users have access to the Laravel-Filemanager. If you are using Middleware or some other approach to enforce security, modify as needed.

 

License

MIT

Links

Chapter 2 of 10