您好我有这个代码从我的服务器下载xls文件到我的电脑:
<?php
class ControllerDescExcel {
public function getExcel() {
$enlace = 'formatoexcel/formatoexcel.xls';
header ("Content-Disposition: attachment; filename=$enlace ");
header ("Content-Type: application/force-download");
header ("Content-Length: ".filesize($enlace));
readfile($enlace);
}
}
?>
但是我的控制台出现了这个错误:
这是xls文件:
抱歉,我的英文。答案 0 :(得分:0)
确保脚本没有生成输出,但readfile()内容除外。
我认为文件名可能不包含路径信息。 &#34; file.xls&#34;没问题,&#34; path / file.xmls&#34;是错的。
Content-Type应为application / vnd.ms-excel
public function getExcel() {
$enlace = 'formatoexcel/formatoexcel.xls';
$file = basename($enlace); // only use file name not path
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="' . $file . '"');
header ("Content-Length: ".filesize($enlace));
readfile($enlace);
}