使用php yii2在Chrome中Excel文件下载失败 [英] Excel file download failed in Chrome using php yii2

查看:88
本文介绍了使用php yii2在Chrome中Excel文件下载失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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.

在上图中,它表明没有文件.

In above picture it shows that there is not file.

任何帮助将不胜感激.

推荐答案

来自

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. 确保您的Internet连接正常工作.如果您的互联网连接不稳定,请学习如何解决互联网稳定性问题.

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

. Chrome会自动恢复下载.您还可以通过单击向下箭头向下箭头,然后依次单击继续"或更多"再单击继续"来恢复文件下载.

. 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.

稍后尝试下载文件.

联系网站所有者.

如果1和2不起作用.而您尝试使用其他浏览器,则问题出在文件和服务器上.

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

您可以通过检查 file_exists 进行修复,并通过以下方式发送文件 Yii2 sendFile .参见示例:

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 .

这篇关于使用php yii2在Chrome中Excel文件下载失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆