vkabachenko / yii2-filepond
Yii2 upload file module based on filepond js library
Installs: 495
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 7
Open Issues: 1
Type:yii2-extension
Requires
- php: ^7.1
- npm-asset/filepond: ^4.4.11
- npm-asset/filepond-plugin-file-encode: ^2.1.4
- npm-asset/filepond-plugin-file-metadata: ^1.0.6
- npm-asset/filepond-plugin-file-poster: ^2.2.0
- npm-asset/filepond-plugin-file-rename: ^1.1.4
- npm-asset/filepond-plugin-file-validate-size: ^2.2.0
- npm-asset/filepond-plugin-file-validate-type: ^1.2.4
- npm-asset/filepond-plugin-image-crop: ^2.0.3
- npm-asset/filepond-plugin-image-edit: ^1.4.0
- npm-asset/filepond-plugin-image-exif-orientation: ^1.0.6
- npm-asset/filepond-plugin-image-preview: ^4.4.0
- npm-asset/filepond-plugin-image-resize: ^2.0.4
- npm-asset/filepond-plugin-image-transform: ^3.4.3
- npm-asset/filepond-plugin-image-validate-size: ^1.2.3
- yiisoft/yii2: ~2.0.14
This package is not auto-updated.
Last update: 2024-12-22 10:01:07 UTC
README
This extension allows you to use Filepond upload js library as a widget in yii2 projects.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require vkabachenko/yii2-filepond
or add
"vkabachenko/yii2-filepond": "dev-master"
to the require section of your composer.json
file.
Usage
Add the extension to the module
section in your config file
'modules' => [
'filepond' => [
'class' => \vkabachenko\filepond\Module::class
]
],
After that you can use Filepond library to upload files in your project.
Single file upload without model
Multiple files upload without model
Multiple files upload with model
Filepond options
Filepond options described at the documentation can be set by setting instanceOptions
or settingsOptions
.
This is the preferred way:
<?= FilepondWidget::widget([
'name' => 'file',
'instanceOptions' => [
'required' => true,
'maxFiles' => 10,
... other options ...
]
]);
?>
Filepond plugins
If you want to add some of filepond plugins to the widget, set the allow plugin option to true
. For example, to add file type validation plugin set allowFileSizeValidation
:
<?= FilepondWidget::widget([
'name' => 'file',
'instanceOptions' => [
'allowFileSizeValidation' => true,
'maxFileSize' => '10M',
... other options ...
]
]);
?>
Validation
Only client-side validation is available. This kind of validation is the part of filepond library. You can add file size and file type validation. Example of file type validation:
<?= FilepondWidget::widget([
'name' => 'file',
'instanceOptions' => [
'allowFileTypeValidation' => true,
'acceptedFileTypes' => ['image/*']
]
... other options ...
]
]);
?>
Localization
Original library isn't localized and has only english labels. This widget has russian translations too. To apply the localization you have to set language
option in Yii
settings or directly in the widget:
<?= FilepondWidget::widget([
'name' => 'file',
'language' => 'ru-RU'
]);
?>
Two or more widget instances on the page
Simply separate widget class definitions.
Widget 1:
<?= FilepondWidget::widget([
'filepondClass' => 'filepond-class-1',
'name' => 'file',
'instanceOptions' => [
... first widget options ...
]
]);
?>
Widget 2:
<?= FilepondWidget::widget([
'filepondClass' => 'filepond-class-2',
'model' => $uploadForm,
'attribute' => 'files[]',
'instanceOptions' => [
... second widget options ...
]
]);
?>