Php 将文件写入服务器磁盘而不是下载

Php 将文件写入服务器磁盘而不是下载,php,Php,我生成的excel如下所示: <?php $file="test.xls"; $test="<table border=1><tr><td>Cell 1</td><td>Cell 2</td></tr></table>"; header("Content-type: application/vnd.ms-excel"); header("Content-Disposition: attachme

我生成的excel如下所示:

<?php
$file="test.xls";
$test="<table border=1><tr><td>Cell 1</td><td>Cell 2</td></tr></table>";
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$file");
echo $test;
?>


它工作得很出色。与其下载到客户端计算机,我可以让它写入服务器中的文件夹吗?

这里有一个将数据写入文件的简单方法,使用您提供的代码,我提供了一个建议性的答案。 各位,现在没有否决权了,这是一个建议性的回答,而且比实际的建议更容易发布

注意:
a
开关将
追加到文件中,
\n
将生成一个新行

<?php
$file = fopen('test.xls', 'a') or die("Unable to open file for output");
$test="<table border=1><tr><td>Cell 1</td><td>Cell 2</td></tr></table>\n";
fwrite($file, $test) or die("Unable to write to file");
fclose($file);
echo "$test"; // echo the output
exit();
?>


file\u put\u contents…?在标题上方使用,下次请在ask.HTML之前搜索文档!==XLS,除非您启用了PHP的automagic扩展,以便从HTML markupi搜索中神奇地创建Excel BIFF文件。所有的事情都告诉我要用一个班级,不过这个很好用。请贴出答案