alexantr/yii2-elfinder
最新稳定版本:1.8.0
Composer 安装命令:
composer require alexantr/yii2-elfinder
包简介
elFinder file manager for Yii 2
README 文档
README
This extension integrates an elFinder 2.1 file manager into Yii framework 2.0.
Installation
Install extension through composer:
composer require alexantr/yii2-elfinder
Usage
Configure actions
For using elFinder you must create and configure controller. See complete example with actions for elFinder's connector,
InputFile widget, CKEditor filebrowser* options and TinyMCE file_picker_callback option:
<?php namespace app\controllers; use alexantr\elfinder\CKEditorAction; use alexantr\elfinder\ConnectorAction; use alexantr\elfinder\InputFileAction; use alexantr\elfinder\TinyMCEAction; use Yii; use yii\web\Controller; class ElfinderController extends Controller { public function actions() { return [ 'connector' => [ 'class' => ConnectorAction::className(), 'options' => [ 'roots' => [ [ 'driver' => 'LocalFileSystem', 'path' => Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR . 'uploads', 'URL' => Yii::getAlias('@web') . '/uploads/', 'mimeDetect' => 'internal', 'imgLib' => 'gd', 'accessControl' => function ($attr, $path) { // hide files/folders which begins with dot return (strpos(basename($path), '.') === 0) ? !($attr == 'read' || $attr == 'write') : null; }, ], ], ], ], 'input' => [ 'class' => InputFileAction::className(), 'connectorRoute' => 'connector', ], 'ckeditor' => [ 'class' => CKEditorAction::className(), 'connectorRoute' => 'connector', ], 'tinymce' => [ 'class' => TinyMCEAction::className(), 'connectorRoute' => 'connector', ], ]; } }
Reed elFinder docs to configure connector options.
InputFile widget
Example of InputFile widget with enabled mime filter and preview:
<?= alexantr\elfinder\InputFile::widget([ 'name' => 'attributeName', 'clientRoute' => 'elfinder/input', 'filter' => ['image'], 'preview' => function ($value) { return yii\helpers\Html::img($value, ['width' => 200]); }, ]) ?>
Note 1: Filter option is using to display only certain files based on their mime type. Check onlyMimes option
in elFinder docs.
Note 2: Preview displays only predefined (saved earlier) input value and not updating on the fly after new selection.
If you want to use the InputFile widget in ActiveForm, it can be done like this:
<?= $form->field($model, 'attributeName') ->widget(alexantr\elfinder\InputFile::className(), [ 'clientRoute' => 'elfinder/input', ]) ?>
Using textarea instead text input (can be useful with enabled multiple selection):
<?= alexantr\elfinder\InputFile::widget([ 'name' => 'attributeName', 'clientRoute' => 'elfinder/input', 'textarea' => true, 'textareaRows' => 3, // default is 5 ]) ?>
Enable multiple selection to select more than one file in one input:
<?= alexantr\elfinder\InputFile::widget([ 'name' => 'attributeName', 'clientRoute' => 'elfinder/input', 'multiple' => true, ]) ?>
Default paths separator for text input is comma and newline character for textarea.
You can change them in InputFileAction configuration:
class ElfinderController extends Controller { public function actions() { return [ // ... 'input' => [ 'class' => InputFileAction::className(), 'connectorRoute' => 'connector', 'separator' => ',', 'textareaSeparator' => '\n', // newline character in javascript ], // ... ]; } }
Integration with CKEditor
For using elFinder with CKEditor widget (like this one) you need to
specify options filebrowserBrowseUrl and (or) filebrowserImageBrowseUrl:
<?= alexantr\ckeditor\CKEditor::widget([ 'name' => 'attributeName', 'clientOptions' => [ // ... 'filebrowserBrowseUrl' => yii\helpers\Url::to(['elfinder/ckeditor']), 'filebrowserImageBrowseUrl' => yii\helpers\Url::to(['elfinder/ckeditor', 'filter' => 'image']), ], ]) ?>
Note: For filebrowserImageBrowseUrl we use filter query param to display only images.
Integration with TinyMCE 4 & 5
For using elFinder with TinyMCE widget (like this one) you need to
specify option file_picker_callback:
<?= alexantr\tinymce\TinyMce::widget([ 'name' => 'attributeName', 'clientOptions' => [ // ... 'file_picker_callback' => alexantr\elfinder\TinyMCE::getFilePickerCallback(['elfinder/tinymce']), ], ]) ?>
Note: option file_picker_callback available since 4.1.0 version of TinyMCE js plugin.
With second param in getFilePickerCallback() you can set additional settings for
tinymce.activeEditor.windowManager.open (TinyMCE 4) or tinymce.activeEditor.windowManager.openUrl (TinyMCE 5):
TinyMCE::getFilePickerCallback(['elfinder/tinymce'], ['width' => 1200, 'height' => 600])
Standalone file manager
Add ElFinder widget to any view:
<?= alexantr\elfinder\ElFinder::widget([ 'connectorRoute' => ['elfinder/connector'], 'settings' => [ 'height' => 640, ], 'buttonNoConflict' => true, ]) ?>
Note: If you are using Bootstrap 3 enable buttonNoConflict option to resolve conflict between
Bootstrap and jQuery UI buttons.
Links
alexantr/yii2-elfinder 适用场景与选型建议
alexantr/yii2-elfinder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 220.53k 次下载、GitHub Stars 达 25, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「elfinder」 「file manager」 「widget」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 alexantr/yii2-elfinder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alexantr/yii2-elfinder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 alexantr/yii2-elfinder 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
A Flysystem Driver for elFinder extended version
Laravel Media Popup to upload/view the files
PMVC Plugin for File information
Laravel Elfinder
Mapper for accessing resources in KWCMS
统计信息
- 总下载量: 220.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 25
- 点击次数: 29
- 依赖项目数: 10
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 未知