Download action only downloading 0 bytes

Hello experts,
I have created an action for downloading. But its only downloading 0 bytes.
action is as below:

  public function actionDownload(){
   $path= Yii::getAlias('@webroot').'\frontend\files';
   $file=$path. '/abc.pdf';
   if (file_exists($file)) {
    Yii::$app->response->xSendFile($file);
   }else{
    return $this->render('index');
         }
  }

Can you help me on this?
Regards,
Siddhartha

Hi Sid,

do you use xSendFile() with installed and configured mod_xsendfile of your Apache webserver?
Also check:

$path= Yii::getAlias('@webroot').'\frontend\files';

Separate your path with / instead of \.

Hello Androphin,
Thanks for your reply, I have not checked in the live shared server environment. I shall check with the vendor.
Same set up is working with my local server.
I believe path separation is ok as it is working with “” in the local server.
I shall get back to you with the results.
Regards,
Siddhartha

Ok but why do you change from \ to / yourself one line later?

Dear Androphin,
Initially I thought about it.
By workaround I found it. But still its working. Though did not checked ‘\abc.pdf’.
Its working in the local server.
Regards,
Siddhartha