使用fopen创建文件和使用标头生成文件有什么区别

时间:2010-10-18 18:13:32

标签: php excel

单程 我用fopen创建了一个xls(“test.xls”)。

使用fwrite我写xls和readfile给我文件。

第二种方式

我用put

生成xls
 header('Cache-Control: no-store, no-cache, must-revalidate');     // HTTP/1.1
    header('Cache-Control: pre-check=0, post-check=0, max-age=0');    // HTTP/1.1
    header ("Pragma: no-cache");
    header("Expires: 0");
    header('Content-Transfer-Encoding: none');
    header("Content-Disposition: attachment; filename=\"test.xls\""); 
    header("Content-Type: application/vnd.ms-excel");

foreach ()

{

echo contents to the file

}

这两种生成文件的方式有什么不同。

有什么区别。

1 个答案:

答案 0 :(得分:1)

您的第一种方法是在服务器文件系统中创建文件,然后通过浏览器提供。该文件保留在那里(除非你有额外的代码在之后删除它)。

您的第二种方法似乎并未在文件系统中创建实际文件,它会动态生成数据 - 然后浏览器将其保存到文件中。

这就是你问的问题吗?