I\'m using Krajee the Bootstrap File Input plugin to perform an upload via AJAX call.
Here is the link to the Krajee plugin AJAX section: Krajee plugin AJAX
The
field($model, 'icon_path')->widget(FileInput::classname(), [
'options' => ['accept' => 'image/*','multiple'=>false, 'id' => 'category_icon_image'],
'pluginLoading' => false,
'pluginOptions' => [
'initialPreview' => (!$model->isNewRecord) ? [
'web/filebox/'.$model->icon_path
] : '',
'initialPreviewAsData' => true,
'browseIcon' => ' ',
'showPreview' => true,
'showCaption' => false,
'showRemove' => false,
'showUpload' => false,
'showClose' => false,
'previewTemplates' => 'object',
'layoutTemplates' => 'preview',
'uploadUrl' => 'category-item/category-item/ajax-image-upload',
'uploadAsync' => false,
'deleteUrl' => Url::toRoute('category-item/delete-image?id='.$model->category_item_id)
],
'pluginEvents' => [
'filebatchuploadsuccess' => 'function(event, data, previewId, index) {
console.log(data.response)
}',
'filebatchselected' => "function(event,files){
var input = $('#category_icon_image');
input.fileinput('upload');
$('#categoryitem-icon_path_pre').val(files[0].name);
}",
],
])
?>