yii2 return json and file downloads

JSON

The controller can call json return data format, data which is not required json

As a method of adding the controller:

public function actionRemoveImage($id){
    Yii::$app->response->format = yii\web\Response::FORMAT_JSON;
    Yii::$app->response->data = [
        'status' => true
    ];
}

yii2 Download file

Yii2 method of using the sendfile

function actionDownload()
{
    $imgFullPath = 'picture.jpg';
    return Yii::$app->response->sendFile($imgFullPath);
}
References
  1. How add one more button to yii2-widget-fileinput?

yii2 file input If you need to remove the effect, to configure initialPreviewConfigparameters

Guess you like

Origin www.cnblogs.com/fsong/p/11260230.html