php如何导出word

时间:2026-02-12 02:20:11

1、新建文件编辑如下代码:

$result = file_get_contents('./test.php');


echo "$result";
//打开缓冲区
ob_start();
//设置缓存区类型
Header("Cache-Control: public");
//设置下载类型
Header("Content-type: application/octet-stream");
//定义范围单位
Header("Accept-Ranges: bytes");
//设置文件名
Header('Content-Disposition: attachment; filename=test.doc');
//不使用缓存
Header("Pragma:no-cache");
//过期时间
Header("Expires:0");
//输出到浏览器
ob_end_flush();

php如何导出word

2、浏览器访问文件,发现生成了word文档,结果如下图:

php如何导出word

3、下载文件,打开查看内容:

php如何导出word

© 2026 途途旅游
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com