php 文件下载的相关代码 兼容所有浏览器
$params=$this->_getAllParams();
$filename=$params['fname'];//文件的原始名字
$encoded_filename=str_replace('+', '%20', urlencode($filename));
$url=$params['furl'];
$ua = $_SERVER["HTTP_USER_AGENT"];
if (file_exists($url)) {
ob_end_clean();//这里要clean一下不然文件内容会多处四个空行
header('Content-Type: application/octet-stream');
if (preg_match("/MSIE/", $ua)) {//IE情况
header('Content-Disposition: attachment; filename="' . $encoded_filename. '"');
} else if (preg_match("/Firefox/", $ua)) {//火狐
header('Content-Disposition: attachment; filename*="utf8\'\'' . $filename . '"');
} else {
header('Content-Disposition: attachment; filename="' . $filename . '"');
}
header('Content-Length: ' . filesize($url));
ob_end_clean();//这里要clean一下不然文件内容会多处四个空行
readfile($url);
flush();
}
相关内容可以查看:http://www.jb51.net/article/26196.htm
其实也可以在.htaccess 加入AddType application/octet-stream .txt 之类的