doris/yii2-upload-file
Composer 安装命令:
composer require doris/yii2-upload-file
包简介
File Uploader Widget with BS4
关键字:
README 文档
README
File Uploader Widget
Installation
The preferred way to install this extension is through composer.
Either run
composer require doris/yii2-upload-file 'dev-master'
or add
"doris/yii2-upload-file": "dev-master"
to the require section of your composer.json file.
yii2-upload-file
Required params
model - required ( object - \yii\db\ActiveRecord )
form - required ( object - \yii\widgets\ActiveForm )
uploadType - required (allow types are - Uploader::UPLOAD_TYPE_IMAGE | Uploader::UPLOAD_TYPE_VIDEO | Uploader::UPLOAD_TYPE_FILE | Uploader::UPLOAD_TYPE_AUDIO )
language - required ( allow languages are - en-US | ru-RU | uk-UA )
attributes - required (array, attribute - needs for saving file name to db and validate (in model rules), tempAttribute needs for transfer uploaded file from asociative array $_FILES, it is public property in your model)
uploadPath - required (type string)
Additional properties
moduleName - not required, if you use basic version Yii2 you must set muduleName (it is name of you admin module, you may find it in your config file).
urlOptions - not required (by default uploadUrl => upload-file, deleteUrl => delete-file), you may set your custom urls and determine them in your controller
options => [
1) multiple - by default false,
2) uploadMineType - depends on param uploadType, if this option will not be specified upload file widget automaticaly determine uploadMineType.
You may set another mineTypes using doris\uploadFile\helpers\UploadHelper.
There where some methods fo set mine types:
- UploadHelper::uploadMineTypeForImages()
- UploadHelper::uploadMineTypeForVideo()
- UploadHelper::uploadMineTypeForAudio()
Or set your custom mine type in string format
3) maxFileSize - this property indicated in the format integer or double, by default 3 MB (example 3, 0.2 ....)
4) resize - [
'resizeWidth' => 450,
'resizeHeight' => 450,
]
Proportional resize by width and height - only for 'uploadType' => Uploader::UPLOAD_TYPE_IMAGE
If resize option was specified you must identify resizeWidth and resizeHeight, they wiil be required.
5) fileMineType => FileUploader::MINE_TYPE_PDF | FileUploader::MINE_TYPE_EXCEL | FileUploader::MINE_TYPE_DOCUMENT
This property works with uploadType => Uploader::UPLOAD_TYPE_FILE, by default have fileMineType value FileUploader::MINE_TYPE_PDF
]
templateOptions => [
1) uploadLimitWindow - show bootstrap alert window with resize information, by default true.
Depends on resize option, if resize option was not specified uploadLimitWindow param will have false value.
2) bootstrapOuterWrapClasses - by default col-xs-12 col-sm-12 col-md-12 col-lg-12, you may set your custom classes.
2) bootstrapInnerWrapClasses - by default col-xs-12 col-sm-12 col-md-12 col-lg-12, you may set your custom classes.
]
NOTE: You must set in params.php domain name (example 'domain' => 'http://example.domain'), for stable generating path for preview.
NOTE: If you using basic version Yii2 you must set moduleName option, for stable generating urls to default processing actions.
Usage
Once the extension is installed, simply use it in your code by :
##Controller
<?php use yii\helpers\ArrayHelper; use doris\uploadFile\actions\UploadFileAction; use doris\uploadFile\actions\DeleteFileAction; class PostController extends \yii\web\Controller { public function actions() { return ArrayHelper::merge(parent::actions(),[ 'upload-file' => ['class' => UploadFileAction::class], //action for uploading file 'delete-file' => ['class' => DeleteFileAction::class], //action for deleting file ]); } } ?>
View
Upload image example
<?php use doris\uploadFile\components\Uploader; use doris\uploadFile\UploadFileWidget; ?> <?= UploadFileWidget::widget([ 'model' => $model, 'form' => $form, 'uploadType' => Uploader::UPLOAD_TYPE_IMAGE, 'language' => 'en-US', 'uploadPath' => 'image/prev', 'attributes' => [ 'attribute' => 'image', 'tempAttribute' => 'tempUploadImage', ], 'options' => [ 'maxFileSize' => 2, 'resize' => [ 'resizeWidth' => 450, 'resizeHeight' => 450, ], ], 'templateOptions' => [ 'uploadLimitWindow' => true, 'bootstrapOuterWrapClasses' => 'col-xs-12 col-sm-12 col-md-6 col-lg-12', 'bootstrapInnerWrapClasses' => 'col-xs-6 col-sm-6 col-md-6 col-lg-12' ] ])?>
Upload video example
<?php use doris\uploadFile\components\Uploader; use doris\uploadFile\UploadFileWidget; ?> <?= UploadFileWidget::widget([ 'model' => $model, 'form' => $form, 'uploadType' => Uploader::UPLOAD_TYPE_VIDEO, 'language' => 'en-US', 'uploadPath' => 'video/video-folder', 'attributes' => [ 'attribute' => 'video', 'tempAttribute' => 'tempUploadVideo', ], 'options' => [ 'maxFileSize' => 2, ], 'templateOptions' => [ 'bootstrapOuterWrapClasses' => 'col-xs-12 col-sm-12 col-md-6 col-lg-12', 'bootstrapInnerWrapClasses' => 'col-xs-6 col-sm-6 col-md-6 col-lg-12' ] ])?>
Upload file example
<?php use doris\uploadFile\components\Uploader; use doris\uploadFile\UploadFileWidget; use doris\uploadFile\components\FileUploader; ?> <?= UploadFileWidget::widget([ 'model' => $model, 'form' => $form, 'uploadType' => Uploader::UPLOAD_TYPE_FILE, 'language' => 'en-US', 'uploadPath' => 'files/file-folder', 'attributes' => [ 'attribute' => 'file', 'tempAttribute' => 'tempUploadFile', ], 'options' => [ 'fileMineType' => FileUploader::MINE_TYPE_DOCUMENT,//FileUploader::MINE_TYPE_DOCUMENT | FileUploader::MINE_TYPE_EXCEL | FileUploader::MINE_TYPE_PDF 'maxFileSize' => 25, ], 'templateOptions' => [ 'bootstrapOuterWrapClasses' => 'col-xs-12 col-sm-12 col-md-6 col-lg-12', 'bootstrapInnerWrapClasses' => 'col-xs-6 col-sm-6 col-md-6 col-lg-12' ] ])?>
Upload audio file example
<?php use doris\uploadFile\components\Uploader; use doris\uploadFile\UploadFileWidget; ?> <?= UploadFileWidget::widget([ 'model' => $model, 'form' => $form, 'uploadType' => Uploader::UPLOAD_TYPE_AUDIO, 'language' => 'en-US', 'uploadPath' => 'audio/audio-folder', 'attributes' => [ 'attribute' => 'file', 'tempAttribute' => 'tempUploadFile', ], 'options' => [ 'maxFileSize' => 25, ], 'templateOptions' => [ 'bootstrapOuterWrapClasses' => 'col-xs-12 col-sm-12 col-md-6 col-lg-12', 'bootstrapInnerWrapClasses' => 'col-xs-6 col-sm-6 col-md-6 col-lg-12' ] ])?>
doris/yii2-upload-file 适用场景与选型建议
doris/yii2-upload-file 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 64 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 06 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「extension」 「yii2」 「uploadfile」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 doris/yii2-upload-file 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 doris/yii2-upload-file 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 doris/yii2-upload-file 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
UI Kit 3 Extension for Yii2
Adds more BBCode
Define your own css rule-sets for the TYPO3 CMS backend.
统计信息
- 总下载量: 64
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-06-26