aik27 / yii2-elfinder
Yii2 ElFinder
Requires
- studio-42/elfinder: ^2.1.10
- yiisoft/yii2: ~2.0.13
- yiisoft/yii2-jui: *
README
ElFinder — 网站文件管理器。
支持的存储
mihaildev/yii2-elfinder-flysystem - https://github.com/MihailDev/yii2-elfinder-flysystem/
Local
Azure
AWS S3 V2
AWS S3 V3
Copy.com
Dropbox
FTP
GridFS
Memory
Null / Test
Rackspace
ReplicateAdapter
SFTP
WebDAV
PHPCR
ZipArchive
安装
最方便的方式是通过 composer 安装。
或者执行
php composer.phar require --prefer-dist aik27/yii2-elfinder "*"
或者在你的 composer.json 文件的 require
部分添加
"aik27/yii2-elfinder": "*"
。
配置
'controllerMap' => [ 'elfinder' => [ 'class' => 'aik27\elfinder\Controller', 'access' => ['@'], //глобальный доступ к фаил менеджеру @ - для авторизорованных , ? - для гостей , чтоб открыть всем ['@', '?'] 'disabledCommands' => ['netmount'], //отключение ненужных команд https://github.com/Studio-42/elFinder/wiki/Client-configuration-options#commands 'roots' => [ [ 'baseUrl'=>'@web', 'basePath'=>'@webroot', 'path' => 'files/global', 'name' => 'Global' ], [ 'class' => 'aik27\elfinder\volume\UserPath', 'path' => 'files/user_{id}', 'name' => 'My Documents' ], [ 'path' => 'files/some', 'name' => ['category' => 'my','message' => 'Some Name'] //перевод Yii::t($category, $message) ], [ 'path' => 'files/some', 'name' => ['category' => 'my','message' => 'Some Name'], // Yii::t($category, $message) 'access' => ['read' => '*', 'write' => 'UserFilesAccess'] // * - для всех, иначе проверка доступа в даааном примере все могут видет а редактировать могут пользователи только с правами UserFilesAccess ] ], 'watermark' => [ 'source' => __DIR__.'/logo.png', // Path to Water mark image 'marginRight' => 5, // Margin right pixel 'marginBottom' => 5, // Margin bottom pixel 'quality' => 95, // JPEG image save quality 'transparency' => 70, // Water mark image transparency ( other than PNG ) 'targetType' => IMG_GIF|IMG_JPG|IMG_PNG|IMG_WBMP, // Target image formats ( bit-field ) 'targetMinPixel' => 200 // Target image minimum pixel size ] ] ],
'controllerMap' => [ 'elfinder' => [ 'class' => 'aik27\elfinder\PathController', 'access' => ['@'], 'root' => [ 'path' => 'files', 'name' => 'Files' ], 'watermark' => [ 'source' => __DIR__.'/logo.png', // Path to Water mark image 'marginRight' => 5, // Margin right pixel 'marginBottom' => 5, // Margin bottom pixel 'quality' => 95, // JPEG image save quality 'transparency' => 70, // Water mark image transparency ( other than PNG ) 'targetType' => IMG_GIF|IMG_JPG|IMG_PNG|IMG_WBMP, // Target image formats ( bit-field ) 'targetMinPixel' => 200 // Target image minimum pixel size ] ] ],
PathController 和 Controller 的区别在于 PathController 只与一个文件夹交互,还有一个额外功能是可以传递请求以打开子目录。
目前仅实现了 LocalFileSystem 存储器(aik27\elfinder\volume\Local 和 aik27\elfinder\volume\UserPath)的使用。要使用其他存储器,你需要通过 aik27\elfinder\volume\Base 进行配置。还添加了扩展 https://github.com/MihailDev/yii2-elfinder-flysystem/,这个扩展允许集成 Flysystem 存储器,如 Local, Azure, AWS S3 V2, AWS S3 V3, Copy.com, Dropbox, FTP, GridFS, Memory, Null / Test, Rackspace, ReplicateAdapter, SFTP, WebDAV, PHPCR, ZipArchive。
配置事件回调
'controllerMap' => [ 'elfinder' => [ ... 'managerOptions' => [ ... 'handlers' => [ 'select' => 'function(event, elfinderInstance) { console.log(event.data); console.log(event.data.selected); }', 'open' => 'function(event, elfinderInstance) {...}', ], ... ], ... ] ],
事件列表 - https://github.com/Studio-42/elFinder/wiki/Client-event-API#event-list
配置插件
由于配置复杂,插件的实现已经重写,但仍然支持使用旧插件。
'controllerMap' => [ 'elfinder' => [ 'class' => 'aik27\elfinder\Controller', //'plugin' => ['\aik27\elfinder\plugin\Sluggable'], 'plugin' => [ [ 'class'=>'\aik27\elfinder\plugin\Sluggable', 'lowercase' => true, 'replacement' => '-' ] ], 'roots' => [ [ 'baseUrl'=>'@web', 'basePath'=>'@webroot', 'path' => 'files/global', 'name' => 'Global', 'plugin' => [ 'Sluggable' => [ 'lowercase' => false, ] ] ], ]
旧插件的配置(以 Sanitizer 插件为例)
'controllerMap' => [ 'elfinder' => [ 'class' => 'aik27\elfinder\Controller', 'connectOptions' => [ 'bind' => [ 'upload.pre mkdir.pre mkfile.pre rename.pre archive.pre ls.pre' => array( 'Plugin.Sanitizer.cmdPreprocess' ), 'ls' => array( 'Plugin.Sanitizer.cmdPostprocess' ), 'upload.presave' => array( 'Plugin.Sanitizer.onUpLoadPreSave' ) ], 'plugin' => [ 'Sanitizer' => array( 'enable' => true, 'targets' => array('\\','/',':','*','?','"','<','>','|'), // target chars 'replace' => '_' // replace to this ) ], ], 'roots' => [ [ 'baseUrl'=>'@web', 'basePath'=>'@webroot', 'path' => 'files/global', 'name' => 'Global', 'plugin' => [ 'Sanitizer' => array( 'enable' => true, 'targets' => array('\\','/',':','*','?','"','<','>','|'), // target chars 'replace' => '_' // replace to this ) ] ], ]
使用
use aik27\elfinder\InputFile; use aik27\elfinder\ElFinder; use yii\web\JsExpression; echo InputFile::widget([ 'language' => 'ru', 'controller' => 'elfinder', // вставляем название контроллера, по умолчанию равен elfinder 'filter' => 'image', // фильтр файлов, можно задать массив фильтров https://github.com/Studio-42/elFinder/wiki/Client-configuration-options#wiki-onlyMimes 'name' => 'myinput', 'value' => '', ]); echo $form->field($model, 'attribute')->widget(InputFile::className(), [ 'language' => 'ru', 'controller' => 'elfinder', // вставляем название контроллера, по умолчанию равен elfinder 'filter' => 'image', // фильтр файлов, можно задать массив фильтров https://github.com/Studio-42/elFinder/wiki/Client-configuration-options#wiki-onlyMimes 'template' => '<div class="input-group">{input}<span class="input-group-btn">{button}</span></div>', 'options' => ['class' => 'form-control'], 'buttonOptions' => ['class' => 'btn btn-default'], 'multiple' => false // возможность выбора нескольких файлов ]); echo ElFinder::widget([ 'language' => 'ru', 'controller' => 'elfinder', // вставляем название контроллера, по умолчанию равен elfinder 'filter' => 'image', // фильтр файлов, можно задать массив фильтров https://github.com/Studio-42/elFinder/wiki/Client-configuration-options#wiki-onlyMimes 'callbackFunction' => new JsExpression('function(file, id){}') // id - id виджета ]);
与 PathController 一起使用
use aik27\elfinder\InputFile; use aik27\elfinder\ElFinder; use yii\web\JsExpression; echo InputFile::widget([ 'language' => 'ru', 'controller' => 'elfinder', // вставляем название контроллера, по умолчанию равен elfinder 'path' => 'image', // будет открыта папка из настроек контроллера с добавлением указанной под деритории 'filter' => 'image', // фильтр файлов, можно задать массив фильтров https://github.com/Studio-42/elFinder/wiki/Client-configuration-options#wiki-onlyMimes 'name' => 'myinput', 'value' => '', ]); echo $form->field($model, 'attribute')->widget(InputFile::className(), [ 'language' => 'ru', 'controller' => 'elfinder', // вставляем название контроллера, по умолчанию равен elfinder 'path' => 'image', // будет открыта папка из настроек контроллера с добавлением указанной под деритории 'filter' => 'image', // фильтр файлов, можно задать массив фильтров https://github.com/Studio-42/elFinder/wiki/Client-configuration-options#wiki-onlyMimes 'template' => '<div class="input-group">{input}<span class="input-group-btn">{button}</span></div>', 'options' => ['class' => 'form-control'], 'buttonOptions' => ['class' => 'btn btn-default'], 'multiple' => false // возможность выбора нескольких файлов ]); echo ElFinder::widget([ 'language' => 'ru', 'controller' => 'elfinder', // вставляем название контроллера, по умолчанию равен elfinder 'path' => 'image', // будет открыта папка из настроек контроллера с добавлением указанной под деритории 'filter' => 'image', // фильтр файлов, можно задать массив фильтров https://github.com/Studio-42/elFinder/wiki/Client-configuration-options#wiki-onlyMimes 'callbackFunction' => new JsExpression('function(file, id){}') // id - id виджета ]);
CKEditor
use aik27\elfinder\ElFinder; $ckeditorOptions = ElFinder::ckeditorOptions($controller,[/* Some CKEditor Options */]);
用于指定子目录(使用 PathController)
use aik27\elfinder\ElFinder; $ckeditorOptions = ElFinder::ckeditorOptions([$controller, 'path' => 'some/sub/path'],[/* Some CKEditor Options */]);
与 "mihaildev/yii2-ckeditor" 应用程序一起使用(https://github.com/MihailDev/yii2-ckeditor)
use aik27\ckeditor\CKEditor; use aik27\elfinder\ElFinder; $form->field($model, 'attribute')->widget(CKEditor::className(), [ ... 'editorOptions' => ElFinder::ckeditorOptions('elfinder',[/* Some CKEditor Options */]), ... ]);
用于指定子目录(使用 PathController)
use aik27\ckeditor\CKEditor; use aik27\elfinder\ElFinder; $form->field($model, 'attribute')->widget(CKEditor::className(), [ ... 'editorOptions' => ElFinder::ckeditorOptions(['elfinder', 'path' => 'some/sub/path'],[/* Some CKEditor Options */]), ... ]);
问题
在没有 iframe 内嵌时,可能会与 bootstrap.js 冲突。解决方法 - 在模板中添加以下记录
aik27\elfinder\Assets::noConflict($this);
有用的链接
ElFinder Wiki - https://github.com/Studio-42/elFinder/wiki
Flysystem
https://github.com/MihailDev/yii2-elfinder-flysystem/
https://github.com/barryvdh/elfinder-flysystem-driver