悠悠楠杉
网站页面
<?php
header("Content-Type: application/octet-stream");
$filename = "1.txt";
$content = '这里是需要生成文件的内容';
$ua = $_SERVER["HTTP_USER_AGENT"];
$encoded_filename = urlencode($filename);
$encoded_filename = str_replace("+", "%20", $encoded_filename);
if (preg_match("/MSIE/", $ua)) {
header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');
} else if (preg_match("/Firefox/", $ua)) {
header('Content-Disposition: attachment; filename*="' . $filename . '"');
} else {
header('Content-Disposition: attachment; filename="' . $filename . '"');
}
echo $content;