dpodium / yii2-filemanager-aws2
Yii2的文件管理器。允许用户从任何位置管理文件,同时也可以在应用程序内浏览文件。
dev-master
2017-09-05 07:52 UTC
Requires
- php: >=5.4.0
- aws/aws-sdk-php: 2.7.18
- fortawesome/font-awesome: *
- kartik-v/yii2-editable: *
- kartik-v/yii2-grid: dev-master
- kartik-v/yii2-widget-activeform: *
- kartik-v/yii2-widget-fileinput: *
- kartik-v/yii2-widgets: *
- yiisoft/yii2: 2.0.*
- yiisoft/yii2-imagine: *
This package is auto-updated.
Last update: 2020-01-12 08:59:22 UTC
README
安装
使用Composer安装
安装此扩展的首选方式是通过Composer。
运行以下命令:
php composer.phar require dpodium/yii2-filemanager-aws2 "dev-master"
或
"dpodium/yii2-filemanager-aws2": "dev-master"
将以下内容添加到您的composer.json
文件的require部分。
在此执行迁移
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', 'prefixPath' => '', 'cacheTime' => '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();