-
-
$ua = $_SERVER["HTTP_USER_AGENT"]; - $filename = "中文文件名.txt";
- $encoded_filename = urlencode($filename);
- $encoded_filename = str_replace("+", "%20", $encoded_filename);
$ua = $_SERVER["HTTP_USER_AGENT"];
- $filename = "中文文件名.txt";
- $encoded_filename = urlencode($filename);
- $encoded_filename = str_replace("+", "%20", $encoded_filename);
- ?>
-
复制代码
以上代码可支持下载中文文件名。
2、生成TXT文件
-
-
- header("Content-Type: application/octet-stream");
- if (preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT']) ) {
- header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');
- } elseif (preg_match("/Firefox/", $_SERVER['HTTP_USER_AGENT'])) {
- header('Content-Disposition: attachment; filename*="utf8' . $filename . '"');
- } else {
- header('Content-Disposition: attachment; filename="' . $filename . '"');
- }
header("Content-Type: application/octet-stream");
- if (preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT']) ) {
- header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');
- } elseif (preg_match("/Firefox/", $_SERVER['HTTP_USER_AGENT'])) {
- header('Content-Disposition: attachment; filename*="utf8' . $filename . '"');
- } else {
- header('Content-Disposition: attachment; filename="' . $filename . '"');
- }//兼容各种浏览器。
- ?>
-
复制代码
3、输出内容
这一步就简单多了,直接用echo输出,“rn”用以换行。
输出的内容即为txt里的内容。
此功能也可以生成doc文件,只要把后缀改成.doc即可,不过按这种方法只能生成简单的doc文件,如果有图片或链接什么的,则只能另寻他途了。
脚本学堂,祝您学习愉快。
|