Excel file download failed in Chrome using php yii2

后端 未结 1 660
粉色の甜心
粉色の甜心 2021-01-25 11:21
Download File

I have a page in which I have a download button that shou

相关标签:
1条回答
  • 2021-01-25 11:59

    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 .

    0 讨论(0)
提交回复
热议问题