What is the File Input Widget?
This widget allows to make use of the great File Input Plugin
that Arnold Daniels developed to enhance our Bootstrap experience.
Installation
The preferred way to install this extension is through composer.
Either run
composer require 2amigos/yii2-file-input-widget:~1.0
or add the following to the require section of your application's composer.json
file:
"2amigos/yii2-file-input-widget" : "~1.0"
Usage example
Using a model:
use dosamigos\fileinput\FileInput;
<?=FileInput::widget([
'model' => $model,
'attribute' => 'image', // image is the attribute
// using STYLE_IMAGE allows me to display an image. Cool to display previously
// uploaded images
'thumbnail' => $model->getAvatarImage(),
'style' => FileInput::STYLE_IMAGE
]);?>
Update
We have also included the improved and multiple file upload js version from Krajee in our assets.
use dosamigos\fileinput\BootstrapFileInput;
<?= $form->field($model, 'code')->widget(BootstrapFileInput::className(), [
'options' => ['accept' => 'image/*', 'multiple' => true],
'clientOptions' => [
'previewFileType' => 'text',
'browseClass' => 'btn btn-success',
'uploadClass' => 'btn btn-info',
'removeClass' => 'btn btn-danger',
'removeIcon' => '<i class="glyphicon glyphicon-trash"></i> '
]
]);?>
For further information regarding Krajee's jQuery version, please visit its site.