第一种:读取已经存在的文件然后输出。
<?php
$filename = "doc.doc";
header("Content-Type: application/msword");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");
readfile($filename);
?>第二种:直接在程序中生成文件内容
<?php
$filename = "doc.doc";
header("Content-Type: application/msword");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");
$title = "word test for " . date("Y-m-d H:i");
echo "$title\r\n";
echo "\tOnly a test\r\n";
?>