LINUNX下PHP下载中文文件名代码

 

        function get_basename($filename){    
            return preg_replace('/^.+[\\\\\\/]/'''$filename);    
         }   
 
        $file "/tmp/你好.txt";
        $filename get_basename($file);
 
        header("Content-type: application/octet-stream");
 
        //处理中文文件名
        $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*=\"utf8''" $filename '"');
        else {
         header('Content-Disposition: attachment; filename="' $filename '"');
        }
     
        header("Content-Length: "filesize($file));
        readfile($file);

posted on 2016-08-17 21:37  ~紫鱼~  阅读(300)  评论(0编辑  收藏  举报