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);

你可能感兴趣的:(LINUNX下PHP下载中文文件名代码)