解决Content-Disposition: 下载中文名乱码,下载乱码
2013-03-19 17:50
274 查看
header('Content-Disposition: attachment; filename*="'. $FileNname . '"');浏览器的不同导致PHP下载中文名乱码。
解决办法如下:
经测试,目前以兼容各主流浏览器。
解决办法如下:
经测试,目前以兼容各主流浏览器。
$lb_sourcefile_name=$_GET['sourcefile']; $down_url=$_GET['operate']; if($_GET['mykey']){ $mykey=$_GET['mykey']; $mykey=str_replace("_","+",$mykey); $mykey=base64_decode($mykey); if($mykey === '2013abcdefg2013lubansoft9527'){ $lb_sourcefile_name=str_replace("_","+",$lb_sourcefile_name); $lb_sourcefile_name=base64_decode($lb_sourcefile_name); $down_url=str_replace("_","+",$down_url); $down_url=base64_decode($down_url); $down_url='../lb/rename_file/'.$down_url; $ua = $_SERVER["HTTP_USER_AGENT"]; header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); if (preg_match("/MSIE/", $ua)) { $lb_sourcefile_name = urlencode($lb_sourcefile_name); $lb_sourcefile_name = str_replace("+", "%20", $lb_sourcefile_name); header('Content-Disposition: attachment; filename="' . $lb_sourcefile_name . '"'); } elseif (preg_match("/Firefox/", $ua)) { header('Content-Disposition: attachment; filename*="utf8\'\'' . $lb_sourcefile_name . '"'); } else { header('Content-Disposition: attachment; filename="' . $lb_sourcefile_name . '"'); } header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($down_url)); ob_clean(); flush(); readfile($down_url); exit; } else{ die(404); } }
相关文章推荐
- 文件下载_中文乱码:"Content-disposition","attachment; filename=中文名
- 探究 Content-Disposition:解决下载中文文件名乱码
- Content-Disposition 文件上传、下载 中文乱码 HTTP头 解决办法 Java Jersey
- 使用Content-Disposition: attachment; filename=FILENAME,在Firefox浏览器中下载文件,文件名中文乱码问题解决。
- 文件下载_中文乱码:"Content-disposition","attachment; filename=中文名
- JavaEE_Web文件下载_lesson2_ JavaEE下载文件,中文乱码解决方法(Content-Disposition)
- 彻底解决中文名文件下载和下载文件内容乱码问题!!!!! (不知道有没有用,我还没有试过)
- 在使用中文名下载文件时文件名出现乱码的解决办法
- 文件下载:"Content-disposition","attachment; filename=中文名>>>解决方案
- 解决Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name) 中文显示乱码
- 解决MVC下载中文名文件乱码问题
- 文件下载:"Content-disposition","attachment; filename=中文名>>>解决方案
- 文件下载Content-disposition(与在文件名文件乱码问题)
- Python下载文件时出现乱码的解决方法之一:Content-Encoding: gzip
- 正确处理下载文件时中文文件名乱码的问题(Content-Disposition)
- 文件下载:"Content-disposition","attachment; filename=中文名>>>解决方案
- 文件下载:"Content-disposition","attachment; filename=中文名>>>解决方案
- Servler下载中文名乱码解决方法
- Android 文件下载中文名乱码的解决办法
- 使用FPT上传下载文件和解决中文名文件乱码问题