Excel下载变成PHP,PHP下载excel文件变得腐败

我有一个excel文件,我希望用户能够从我的服务器下载.我在这里看了很多问题,但我找不到正确下载没有腐败的文件的方法.我假设它是标题但我还没有它们的工作组合.这就是我现在所拥有的,在我收到的损坏文件中,我可以看到我想要的电子表格的列名,但它全部搞砸了.

$filename = '/var/www/web1/web/public/temporary/Spreadsheet.xls';

header("Content-type: application/octet-stream");

header("Content-type: application/vnd-ms-excel");

header("Content-Disposition: attachment; filename=ExcelFile.xls;");

header("Pragma: no-cache");

header("Expires: 0");

readfile($filename);

编辑:解决方案我忘了添加我正在使用Zend,它在尝试使用本机php方法时破坏了文件.我的finsihed代码是在我的控制器中放置一个链接到另一个动作,并从那里下载文件

public function downloadAction(){

$file = '/var/www/web1/web/public/temporary/Spreadsheet.xls';

header('Content-Type: application/vnd.ms-excel');

header('Content-Disposition: attachment; filename="Spreadsheet.xls"');

readfile($file);

// disable the view ... and perhaps the layout

$this->view->layout()->disableLayout();

$this->_helper->viewRenderer->setNoRender(true);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值