dpodium / yii2-filemanager
一个针对Yii2的文件管理器。允许用户从任何位置管理文件,以及在应用内部浏览文件。
dev-develop
2018-10-12 05:37 UTC
Requires
- php: >=5.4.0
- aws/aws-sdk-php: 3.*
- kartik-v/yii2-editable: *
- kartik-v/yii2-grid: dev-master
- kartik-v/yii2-widget-activeform: *
- kartik-v/yii2-widget-fileinput: *
- kartik-v/yii2-widgets: *
- rmrevin/yii2-fontawesome: ~2.17
- yiisoft/yii2: 2.0.*
- yiisoft/yii2-imagine: *
This package is auto-updated.
Last update: 2024-09-12 18:59:17 UTC
README
安装
使用Composer安装
安装此扩展的首选方式是通过composer。
运行以下命令之一:
php composer.phar require dpodium/yii2-filemanager "dev-master"
或者将以下内容添加到您的composer.json
文件的require部分:
"dpodium/yii2-filemanager": "dev-master"
在此处执行迁移
yii migrate --migrationPath=@dpodium/filemanager/migrations
yii migrate/down --migrationPath=@dpodium/filemanager/migrations
使用方法
扩展安装完成后,只需按照以下方式修改您的应用程序配置:
在本地上传文件
return [ 'modules' => [ 'gridview' => [ 'class' => '\kartik\grid\Module' ], 'filemanager' => [ 'class' => 'dpodium\filemanager\Module', 'storage' => ['local'], // This configuration will be used in 'filemanager/files/upload' // To support dynamic multiple upload // Default multiple upload is true, max file to upload is 10 // If multiple set to true and maxFileCount is not set, unlimited multiple upload 'filesUpload' => [ 'multiple' => true, 'maxFileCount' => 30 ], // in mime type format 'acceptedFilesType' => [ 'image/jpeg', 'image/png', 'image/gif', ], // MB 'maxFileSize' => 8, // [width, height], suggested thumbnail size is 120X120 'thumbnailSize' => [120,120] ] ] ];
上传文件到AWS S3
return [ 'modules' => [ 'gridview' => [ 'class' => '\kartik\grid\Module' ], 'filemanager' => [ // do not change module to other name 'class' => 'dpodium\filemanager\Module', // This configuration will be used in 'filemanager/files/upload' // To support dynamic multiple upload // Default multiple upload is true, max file to upload is 10 // If multiple set to true and maxFileCount is not set, unlimited multiple upload 'filesUpload' => [ 'multiple' => true, 'maxFileCount' => 30 ], 'storage' => [ 's3' => [ 'key' => 'your aws s3 key', 'secret' => 'your aws s3 secret', 'bucket' => '', 'region' => '', 'proxy' => '192.168.16.1:10', 'cdnDomain' => '', 'prefixPath' => '', 'cacheTime' => '', // if empty, by default is 2592000 (30 days) ] ], // in mime type format 'acceptedFilesType' => [ 'image/jpeg', 'image/png', 'image/gif', ], // MB 'maxFileSize' => 8, // [width, height], suggested thumbnail size is 120X120 'thumbnailSize' => [120,120] ] ] ];
然后您可以通过以下URL访问文件管理器
http://localhost/path/to/index.php?r=filemanager/folders
http://localhost/path/to/index.php?r=filemanager/files
为了使用文件管理器的浏览功能
use yii\helpers\Html; use yii\widgets\ActiveForm; use dpodium\filemanager\widgets\FileBrowse; // This is just an example to upload a banner $form = ActiveForm::begin(); echo $form->field($model, 'banner_name'); echo $form->field($model, 'banner_description'); // if you would like to store file_identifier in your table echo $form->field($model, 'file_identifier')->widget(FileBrowse::className(), [ 'multiple' => false, // allow multiple upload 'folderId' => 1 // set a folder to be uploaded to. ]); echo Html::submitButton('Submit', ['class' => 'btn btn-primary']); ActiveForm::end(); // !important: modal must be rendered after form echo FileBrowse::renderModal();
为了使用文件管理器与TinyMCE的集成
- 通过composer安装
2amigos/yii2-tinymce-widget
use yii\helpers\Html; use yii\widgets\ActiveForm; use dpodium\filemanager\widgets\FileBrowseEditor; // This is just an example to edit one field $form = ActiveForm::begin(); echo $form->field($model, 'editor')->widget(TinyMce::class, [ 'clientOptions' => [ // add yii2-filemanager to plugin config 'plugins' => [ "... yii2-filemanager ..." ], // optional add yii2-filemanager to toolbar 'toolbar' => "... yii2-filemanager ...", ] ]); echo Html::submitButton('Submit', ['class' => 'btn btn-primary']); ActiveForm::end(); // !important: modal must be rendered after form echo FileBrowseEditor::widget([ 'multiple' => false, // allow multiple upload 'folderId' => 1, // set a folder to be uploaded to. ]);