Q:

Function Download in Yii2

public function actionUnduh($id) {
        $download = PstkIdentifikasi::findOne($id);
        $path = Yii::getAlias('../web/bukti/') . $download->bukti;

        if (file_exists($path)) {
            //return \Yii::$app->response->sendFile($download->pre_paper,@file_get_contents($path));
            return Yii::$app->response->sendFile($path);
        }
    }  

I need to download file from folder web/bukti, the code not error but the code doesn't work, Anyone can help me :(

A:

public function actionUnduh($id) 
{ 
    $download = PstkIdentifikasi::findOne($id); 
    $path = Yii::getAlias('@webroot').'/bukti/'.$download->bukti;

    if (file_exists($path)) {
        return Yii::$app->response->sendFile($path, 'File name here');
    }
}

Refer below:
Yii2 Aliases
Yii2 sendFile()

