+
80
-

php如何echo下载文本文件?

php
php如何echo下载文本文件?

网友回复

+
0
-
<?php
$ua = $_SERVER["HTTP_USER_AGENT"];
$filename = "中文文件名.txt";
$encoded_filename = urlencode($filename);
$encoded_filename = str_replace("+", "%20", $encoded_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 . '"');
}
echo "这里是文本
\n新的一行";

我知道答案,我要回答