Download the PHP package weison-tech/yii2-file-kit without Composer
On this page you can find all versions of the php package weison-tech/yii2-file-kit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download weison-tech/yii2-file-kit
More information about weison-tech/yii2-file-kit
Files in weison-tech/yii2-file-kit
Package yii2-file-kit
Short Description Yii2 file upload and storage kit
License BSD-3-Clause
Informations about the package yii2-file-kit
This kit is designed to automate routine processes of uploading files, their saving and storage. It includes:
- File upload widget (based on Blueimp File Upload)
- Component for storing files (built on top of flysystem)
- Actions to download, delete, and view (download) files
- Behavior for saving files in the model and delete files when you delete a model
Here you can see list of available filesystem adapters
Demo
Since file kit is a part of yii2-starter-kit it's demo can be found in starter kit demo here.
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json
file.
File Storage
To work with the File Kit you need to configure FileStorage first. This component is a layer of abstraction over the filesystem
- Its main task to take on the generation of a unique name for each file and trigger corresponding events.
There are several ways to configure trntv\filekit\Storage
to work with flysystem
.
Using Closure
Using filesystem builder
- Create a builder class that implements
trntv\filekit\filesystem\FilesystemBuilderInterface
and implement methodbuild
which returns filesystem object. Seeexamples/
- Add to your configuration:
Read more about flysystem at http://flysystem.thephpleague.com/
Using third-party extensions
-
Create filesystem component (example uses
creocoder/yii2-flysystem
) - Set filesystem component name in storage configuration:
Actions
File Kit contains several Actions to work with uploads.
Upload Action
Designed to save the file uploaded by the widget
See additional settings in the corresponding class
Delete Action
See additional settings in the corresponding class
View (Download) Action
See additional settings in the corresponding class
Upload Widget
Standalone usage
With ActiveForm
Upload Widget events
Upload widget trigger some of built-in blueimp events:
- start
- fail
- done
- always
You can use them directly or add your custom handlers in options:
UploadBehavior
This behavior is designed to save uploaded files in the corresponding relation.
Somewhere in model:
For multiple files
For single file upload
See additional settings in the corresponding class.
Validation
There are two ways you can perform validation over uploads. On the client side validation is performed by Blueimp File Upload. Here is documentation about available options.
On the server side validation is performed by [[yii\web\UploadAction]], where you can configure validation rules for [[yii\base\DynamicModel]] that will be used in validation process
Tips
Adding watermark
Install intervention/image
library
Edit your upload actions as so
All versions of yii2-file-kit with dependencies
yiisoft/yii2-jui Version ^2.0.0
league/flysystem Version ^1.0
bower-asset/blueimp-file-upload Version ^9.7.0