PHP header下载文件中文名乱码

PT站以前用的环境是lnmp集成环境,现在是原生的apache、php、mysql,话说换了环境才知道lnmp本土化做的真不错 以前很正常的功能现在出现了一些bug,种子下载就出现了问题,下载文件名出现中文乱码的情况,不用说又是编码问题。 先晒一下以前的代码:
header("Content-Type: application/x-bittorrent");
if ( str_replace("Gecko", "", $_SERVER['HTTP_USER_AGENT']) != $_SERVER['HTTP_USER_AGENT'])
{	
	header ("Content-Disposition: attachment; filename=\"$torrentnameprefix.".$row["save_as"].".torrent\"; charset=utf-8");
}
else if ( str_replace("Firefox", "", $_SERVER['HTTP_USER_AGENT']) != $_SERVER['HTTP_USER_AGENT'] )
{
	header ("Content-Disposition: attachment; filename=\"$torrentnameprefix.".$row["save_as"].".torrent\"; charset=utf-8");
}
else if ( str_replace("Opera", "", $_SERVER['HTTP_USER_AGENT']) != $_SERVER['HTTP_USER_AGENT'] )
{
	header ("Content-Disposition: attachment; filename=\"$torrentnameprefix.".$row["save_as"].".torrent\"; charset=utf-8");
}
else if ( str_replace("IE", "", $_SERVER['HTTP_USER_AGENT']) != $_SERVER['HTTP_USER_AGENT'] )
{
	header ("Content-Disposition: attachment; filename=".str_replace("+", "%20", rawurlencode("$torrentnameprefix." . $row["save_as"] .".torrent")));
}
else
{
	header ("Content-Disposition: attachment; filename=".str_replace("+", "%20", rawurlencode("$torrentnameprefix." . $row["save_as"] .".torrent")));
}
print(benc($dict));
换成新环境就不行了,只要是中文就乱码,尝试使用header("Content-type:text/html;charset=utf-8");还有iconv("utf-8","gbk",$row["save_as"]);最终无果,然后各种Google,baidu还是不行,很多文章都是千篇一律,试了好多遍,最终找到解决方案,不过在IE9下面还是有些问题。
header("Content-Type: application/x-bittorrent");
header("Content-Disposition: attachment; filename=" . "$torrentnameprefix." . rawurlencode($row["save_as"] .".torrent") . ";filename*=". "$torrentnameprefix." . rawurlencode($row["save_as"] .".torrent"));
print(benc($dict));