我有一个 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 方法时它会损坏文件。我完成的代码是在我的控制器中放置一个指向另一个操作的链接,并从那里下载文件
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();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)