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


Write file to server disk instead of downloading

我生成了一个这样的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开关,将append转到文件中,'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();
?>