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);


    }

解决方法

试着这样做

ob_get_clean();
 echo file_get_contents($filename);
 ob_end_flush();

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...