php导出doc文件_php生成word文档并下载
在php程序文件中生成內容到word文檔中并提供下載功能的實現代碼
1.前端代碼
PHP生成Word文檔xxx的簡歷
編號:000001
| 姓名 | xxx | 學歷 | xxx |
| ||||||||
| 性別 | xxx | 出生年月 | xxx | 戶籍地 | xxx | |||||||
| 身高 | xxxcm | 體重 | xxxkg | 婚姻狀況 | xxx | |||||||
| 手機 | xxx | xxx | ||||||||||
| 家庭住址 | xxx | |||||||||||
| 求職意向 | 希望從事職業 | xxx | 希望薪資 | xxx元/月 | ||||||||
| 希望工作地區 | xxx | 食宿要求 | xxx | |||||||||
| 目前狀況 | xxx | |||||||||||
| 自我評價 | xxx | |||||||||||
| 工作經歷 | xxx | |||||||||||
| 教育經歷 | xxx | |||||||||||
| 培訓經歷 | xxx | |||||||||||
點擊下載
后臺代碼:
//獲取1.html文檔的內容(包括html代碼)
$result = file_get_contents('./1.html');
echo "$result";
// /保存///
//打開緩沖區
ob_start();
header("Cache-Control: public");
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
//判斷瀏覽器類型
if (strpos($_SERVER["HTTP_USER_AGENT"],'MSIE')) {
header('Content-Disposition: attachment; filename=test.doc');
}else if (strpos($_SERVER["HTTP_USER_AGENT"],'Firefox')) {
Header('Content-Disposition: attachment; filename=test.doc');
} else {
header('Content-Disposition: attachment; filename=test.doc');
}
//不使用緩存
header("Pragma:no-cache");
//過期時間
header("Expires:0");
//輸出全部內容到瀏覽器
ob_end_flush();
?>
網頁運行結果:
原理:
首先獲取到要下載的前端頁面的html代碼(file_get_contents方法),然后對文檔流進行相關配置,最后輸出即可。
總結
以上是生活随笔為你收集整理的php导出doc文件_php生成word文档并下载的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Redis Cluster集群搭建
- 下一篇: php smarty 后台,PHP Sm