防止下载文件名 及 内容乱码

浏览:2184 最后更新:2016-03-28 17:35 分类:其他
/**
* 功能: 文件下载
* @param $filename 文件名称
* @param $file_path 文件路径
*/
function downFile($filename){
$file_path = iconv('UTF-8', 'gb2312', $filename);
$ua = $_SERVER["HTTP_USER_AGENT"];
$encoded_filename = urlencode($filename);
$encoded_filename = str_replace("+", "%20", $encoded_filename);
header('Content-Type:application/octet-stream');
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 .'"');
}
readfile($file_path);
}
评论( 相关
后面还有条评论,点击查看>>