PHP导出一个txt文本文件

1.首先处理好写入txt文件的内容,特别注意编码问题,能够用mb_convert_encoding函数处理编码问题;

2.引入头文件;

3.输出内容,能够直接下载到本地。

$content = "文本内容"//文件内容
header("Content-type: application/octet-stream"); 
header("Accept-Ranges: bytes"); 
header("Content-Disposition: attachment; filename = test.txt"); //文件命名
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Pragma: public"); 
echo $content;
复制代码

欢迎大佬们指点!!!

相关文章
相关标签/搜索