我需要xlsx
从我的网站下载文件(但不是像这样直接打开文件网址http://site.com/file.xlsx
:)
所以,这是php代码
$file = "somefile.xlsx";
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
文件已下载,他的扩展名是.xlsx
,但是当尝试在 ms excel 中打开此文件时,文件未打开并且出现错误:excel cannot open the file.xlsx because the file format or file extension is not valid
请告诉我,为什么会这样?我错在哪里?