1
<a href="/Files/file.xxxx" download class="btn btn-success">Download File</a>

I have a page in which I have a download button that should download the file. But it failed to download. I have checked this issue but didn't find any solution.

enter image description here

In above picture it shows that there is not file.

Any help would be highly appreciated.

Moeez
  • 494
  • 9
  • 55
  • 147

1 Answers1

1

From google chrome help center

If you try to download a file and it doesn’t work, first try to fix the error with these troubleshooting steps:

  1. Make sure your internet connection is working normally. If your internet connection is unstable, learn how to fix internet stability issues.

    . Chrome will automatically resume the download. You can also resume the file download by clicking the Down arrow Down Arrow and then Resume or More More and then Resume.

  2. Try to download the file later.

  3. Contact the website owner.

If 1 and 2 not work. and you trying with other browsers then the problem is in your file and server.

You can fix it by checking file_exists and send file by Yii2 sendFile. see example:

$file_path = '/route/to/path/file.xlsx';
if (file_exists($file_path)) {
    return Yii::$app->response->sendFile($file_path);
}else{
    return 'file not found';
}

you can use this code in any controller .

ttrasn
  • 4,322
  • 4
  • 26
  • 43
  • Hi, Sorry for excepting too late but it does solves my issue – Moeez Nov 19 '20 at 08:35
  • Can you please look into one of my new [question](https://stackoverflow.com/q/64906846/6854117) that is related to the path ? – Moeez Nov 19 '20 at 08:36