I put the file to download in the web folder(publically accessible), I tried different approch to get it downloaded but getting 0byte file:
The first thing I tried(file is being downloaded but 0byte; and if I open, the message is saying file corrupted) :
public function actionImage(){
\Yii::$app->response->xSendFile('Image.zip');
}
The seconde(getting 500 internal error) :
public function actionImage(){
header('application/zip');
header('Content-Disposition:attachment;filename=Image.zip');
$path =Yii::getAlias("@webroot/Image.zip");
//echo $path; gives the path
//echo filesize($path.$file); is returning the file size
header('X-Sendfile: '.$path.$file); // $path.$file outside quotes
header('Content-Length: '.filesize($path.$file)); // Filesize
Yii::$app->end();
}
But if I type directly mydomain.com/Image.zip, it is downloading the file.
I don’t know how to process so that xsendfile works for me!!