Skip to content

Configuring File Uploads

Coackroach edited this page Apr 12, 2019 · 1 revision

You can configure file upload field by using the type option under the fieldConfig and if you want to support multiple file uploads then you should use the multifield as true under the specific field to support multiple file uploads, otherwise omit it.

[
    'model'=>$model
    'title'=>'Images',
    'description'=>'Give us the details of the list',
    'formInfoText'=>'Fill all required fields',
    'fieldConfig' => [
        'image' => [
            'type'=>'file',
            'multifield'=>true,
        ]
    ]
],

Using Widgets for File Uploads

For using the widget you dont need to configure the type property for the field, but if you want the multiple file uploads then you should specify the "multifield"=>true, otherwise omit.

See the below code where you can use the kartik\FileInput widget

[
    'model'=>$model,
    'title'=>'Images',
    'description'=>'Give us the details of the list',
    'formInfoText'=>'Fill all required fields',
    'fieldConfig' => [
        'image' => [
            'multifield'=>true,
            'widget' => FileInput::classname(),
            'options' =>[
                'options' => [
                    'multiple' => true,
                    'accept' => 'image/*',
                    'pluginOptions' => [
                        'showCaption' => false,
                        'showRemove' => false,
                        'showUpload' => false,
                        'browseClass' => 'btn btn-primary btn-block',
                        'browseIcon' => '<i class="glyphicon glyphicon-camera"></i> ',
                        'browseLabel' =>  'Attach Listing Images',
                        'allowedFileExtensions' => ['jpg','gif','png'],
                        'overwriteInitial' => false
                    ],
                ],
            ],
        ]
    ]
],
Clone this wiki locally