2017 © Pedro Peláez
 

library laravel-elfinder

A Laravel Package to integrate elFinder 2

image

barryvdh/laravel-elfinder

A Laravel Package to integrate elFinder 2

  • Thursday, February 8, 2018
  • by Barryvdh
  • Repository
  • 27 Watchers
  • 498 Stars
  • 482,434 Installations
  • PHP
  • 42 Dependents
  • 1 Suggesters
  • 136 Forks
  • 122 Open issues
  • 19 Versions
  • 9 % Grown

The README.md

elFinder Package for Laravel

For Laravel 8.x and older, please use the latest 0.4 version.

Packagist License Latest Stable Version Total Downloads, (*1)

This packages integrates elFinder, by making the php files available with Composer (+autoloading) and the assets with a publish command. It also provides some example views for standalone, tinymce and ckeditor. Files are updated from the a seperate build repository, (*2)

Note: Use php artisan elfinder:publish instead of the old publish command, for future changes!, (*3)

image, (*4)

Installation

Require this package with Composer, (*5)

composer require barryvdh/laravel-elfinder

You need to copy the assets to the public folder, using the following artisan command:, (*6)

php artisan elfinder:publish

Remember to publish the assets after each update (or add the command to your post-update-cmd in composer.json), (*7)

Routes are added in the ElfinderServiceProvider. You can set the group parameters for the routes in the configuration. You can change the prefix or filter/middleware for the routes. If you want full customisation, you can extend the ServiceProvider and override the map() function., (*8)

Configuration

The default configuration requires a directory called 'files' in the public folder. You can change this by publishing the config file., (*9)

php artisan vendor:publish --provider='Barryvdh\Elfinder\ElfinderServiceProvider' --tag=config

In your config/elfinder.php, you can change the default folder, the access callback or define your own roots., (*10)

Views

You can override the default views by copying the resources/views folder. You can also do that with the vendor:publish command:, (*11)

php artisan vendor:publish --provider='Barryvdh\Elfinder\ElfinderServiceProvider' --tag=views

Using Filesystem disks

Laravel has the ability to use Flysystem adapters as local/cloud disks. You can add those disks to elFinder, using the disks config., (*12)

This examples adds the local disk and my-disk:, (*13)

'disks' => [
    'local',
    'my-disk' => [
        'URL' => url('to/disk'),
        'alias' => 'Local storage',
    ]
],

You can add an array to provide extra options, like the URL, alias etc. Look here for all options. If you do not provide an URL, the URL will be generated by the disk itself., (*14)

Using Glide for images

See elfinder-flysystem-driver for Glide usage. A basic example with a custom Laravel disk and Glide would be:, (*15)

  1. Add the disk to your apps config/filesystems disks:, (*16)

    'public' => [
       'driver' => 'local',
       'root'   => base_path().'/public',
    ],
    

    Tip: you can use the extend method to register your own driver, if you want to use non-default Flysystem disks, (*17)

  2. Create a Glide Server for your disk, eg. on the glide/<path> route, using a cache path:, (*18)

    Route::get('glide/{path}', function($path){
       $server = \League\Glide\ServerFactory::create([
           'source' => app('filesystem')->disk('public')->getDriver(),
       'cache' => storage_path('glide'),
       ]);
       return $server->getImageResponse($path, Input::query());
    })->where('path', '.+');
    
  3. Add the disk to your elfinder config:, (*19)

    'disks' => [
       'public' => [
           'glideURL' => '/glide',
       ],
    ],
    
  4. (Optional) Add the glideKey also to the config, and verify the key in your glide route using the Glide HttpSignature., (*20)

You should now see a root 'public' in elFinder with the files in your public folder, with thumbnails generated by Glide. URLs will also point to the Glide server, for images., (*21)

TinyMCE 5.x

You can use tinyMCE 5 integration with the following route /elfinder/tinymce5:, (*22)

route('elfinder.tinymce5');

In the TinyMCE init code, add the following line:, (*23)

file_picker_callback : elFinderBrowser

Then add the following function (change the elfinder_url to the correct path on your system):, (*24)

function elFinderBrowser (callback, value, meta) {
    tinymce.activeEditor.windowManager.openUrl({
        title: 'File Manager',
        url: elfinder_url,
        /**
         * On message will be triggered by the child window
         * 
         * @param dialogApi
         * @param details
         * @see https://www.tiny.cloud/docs/ui-components/urldialog/#configurationoptions
         */
        onMessage: function (dialogApi, details) {
            if (details.mceAction === 'fileSelected') {
                const file = details.data.file;

                // Make file info
                const info = file.name;

                // Provide file and text for the link dialog
                if (meta.filetype === 'file') {
                    callback(file.url, {text: info, title: info});
                }

                // Provide image and alt text for the image dialog
                if (meta.filetype === 'image') {
                    callback(file.url, {alt: info});
                }

                // Provide alternative source and posted for the media dialog
                if (meta.filetype === 'media') {
                    callback(file.url);
                }

                dialogApi.close();
            }
        }
    });
}

TinyMCE 4.x

You can use tinyMCE integration with the following route, which by default is /elfinder/tinymce4:, (*25)

route('elfinder.tinymce4');

In the TinyMCE init code, add the following line:, (*26)

file_browser_callback : elFinderBrowser

Then add the following function (change the elfinder_url to the correct path on your system):, (*27)

function elFinderBrowser (field_name, url, type, win) {
  tinymce.activeEditor.windowManager.open({
    file: '<?= route('elfinder.tinymce4') ?>',// use an absolute path!
    title: 'elFinder 2.0',
    width: 900,
    height: 450,
    resizable: 'yes'
  }, {
    setUrl: function (url) {
      win.document.getElementById(field_name).value = url;
    }
  });
  return false;
}

TinyMCE 3.x

You can add tinyMCE integration with the following route (default: /elfinder/tinymce):, (*28)

route('elfinder.tinymce');

In the TinyMCE init code, add the following line:, (*29)

file_browser_callback : 'elFinderBrowser'

Then add the following function (change the elfinder_url to the correct path on your system):, (*30)

function elFinderBrowser (field_name, url, type, win) {
  var elfinder_url = '/elfinder/tinymce';    // use an absolute path!
  tinyMCE.activeEditor.windowManager.open({
    file: elfinder_url,
    title: 'elFinder 2.0',
    width: 900,
    height: 450,
    resizable: 'yes',
    inline: 'yes',    // This parameter only has an effect if you use the inlinepopups plugin!
    popup_css: false, // Disable TinyMCE's default popup CSS
    close_previous: 'no'
  }, {
    window: win,
    input: field_name
  });
  return false;
}

CKeditor 4.x

You can add CKeditor integration with the following route:, (*31)

'elfinder.ckeditor'

In the CKeditor config file:, (*32)

config.filebrowserBrowseUrl = '/elfinder/ckeditor';

Standalone Popup Selector

To use elFinder by using a href, button or other element to trigger a popup window, you will need to do the following., (*33)

Add support for a popup window, we have used Jacklmoore's jQuery colorbox, (Not included), but you could use any other, obviously adjusting the following instructions accordingly., (*34)

Add required routes

You can add the popup with the following action:, (*35)

'Barryvdh\Elfinder\ElfinderController@showPopup'

Add the required resources

Be Sure that you have published this packages public assets as described above. Then within the <head> section of your page include the required colorbox styles (we suggest example1' styles, but any will do), (*36)

<link href="/assets/css/colorbox.css" rel="stylesheet">

Colorbox depends on jQuery, so ensure that you have it included within your page, then somewhere after your jQuery file has been included, add the script for jQuery Colorbox, such as..., (*37)

<script type="text/javascript" src="/assets/js/jquery.colorbox-min.js"></script>

Now add a link to the popup script, just before the close of your <body> tag. A non-minified version is also provided, for if you wish to modify the colorbox config. Simply copy to your assets location, and adjust/minify as desired., (*38)

<script type="text/javascript" src="/packages/barryvdh/elfinder/js/standalonepopup.min.js"></script>

Usage

In order to use the finder to populate an input, simply add your input that you wish to be populated, ensuring to use an ID (This will be used to update the value once a file/image has been selected)......, (*39)

<label for="feature_image">Feature Image</label>
<input type="text" id="feature_image" name="feature_image" value="">

Now just add the element that you wish to use to trigger the popup, ensuring to add the class popup_selector and the data-inputid atribute containing the value matching the id of your input you wish to be populated, as below., (*40)

<a href="" class="popup_selector" data-inputid="feature_image">Select Image</a>

You can have as many elements as you wish on the page, just be sure to provide each with a unique ID, and set the data-updateid attribute on the selector accordingly., (*41)

The Versions

18/08 2016
04/04 2016
17/03 2016

v0.3.6

0.3.6.0

A Laravel Package to integrate elFinder 2

  Sources   Download

MIT

The Requires

 

laravel tinymce elfinder filebrowser

22/12 2015

v0.3.5

0.3.5.0

A Laravel Package to integrate elFinder 2

  Sources   Download

MIT

The Requires

 

laravel tinymce elfinder filebrowser

26/06 2015

0.2.x-dev

0.2.9999999.9999999-dev

A Laravel Package to integrate elFinder 2

  Sources   Download

MIT

The Requires

 

laravel tinymce elfinder filebrowser

07/06 2015

v0.3.4

0.3.4.0

A Laravel Package to integrate elFinder 2

  Sources   Download

MIT

The Requires

 

laravel tinymce elfinder filebrowser

09/04 2015

v0.3.3

0.3.3.0

A Laravel Package to integrate elFinder 2

  Sources   Download

MIT

The Requires

 

laravel tinymce elfinder filebrowser

26/03 2015

v0.3.2

0.3.2.0

A Laravel Package to integrate elFinder 2

  Sources   Download

MIT

The Requires

 

laravel tinymce elfinder filebrowser

13/03 2015

v0.3.1

0.3.1.0

A Laravel Package to integrate elFinder 2

  Sources   Download

MIT

The Requires

 

laravel tinymce elfinder filebrowser

05/02 2015

v0.3.0

0.3.0.0

A Laravel Package to integrate elFinder 2

  Sources   Download

MIT

The Requires

 

laravel tinymce elfinder filebrowser

03/12 2014

v0.2.0

0.2.0.0

A Laravel Package to integrate elFinder 2

  Sources   Download

MIT

The Requires

 

laravel tinymce elfinder filebrowser

14/08 2014

v0.1.2

0.1.2.0

A Laravel Package to integrate elFinder 2

  Sources   Download

The Requires

 

laravel tinymce elfinder filebrowser

23/04 2014

v0.1.1

0.1.1.0

A Laravel Package to integrate elFinder 2

  Sources   Download

The Requires

 

laravel tinymce elfinder filebrowser

16/01 2014

v0.1

0.1.0.0

A Laravel Package to integrate elFinder 2

  Sources   Download

The Requires

 

laravel tinymce elfinder filebrowser