2013-05-28 29 views
0

我生成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; 
?> 

它的工作出色。而不是它下载到客户端计算机,我可以写它到服务器中的文件夹?

+2

file_put_contents ...? – bwoebi

+0

上面的头文件使用['file_put_contents()'](http://uk.php.net/file_put_contents),下一次请在搜索之前搜索文档。 – HamZa

+0

HTML!== XLS除非你有PHP的automagic扩展功能,可以从HTML标记中奇迹般地创建一个Excel BIFF文件 –

回答

1

这里有一个简单的方法来写入数据到文件,并使用您提供的代码,提供暗示答案。 现在没有下调的人,这是一个暗示的答案,并且比实际建议更容易发布。

注意: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(); 
?> 
相关问题