An error occurred while exporting the Chinese file name in phpexcel-php Tutorial

Source: Internet
Author: User
An error occurred while exporting the Chinese file name in phpexcel. header ("Content-Disposition: attachment; filename = $ filename ");
$ If filename is Chinese, the downloaded file is. php in English.


Reply to discussion (solution)

Try

    $user_agent = $_SERVER['Http_User_agent'];      $encode_filename = rawurlencode($filename);     if(preg_match("/MSIE/", $user_agent)){          header('content-disposition:attachment; filename="'.$encode_filename.'"');      }else if(preg_match("/Firefox/", $user_agent)){          header("content-disposition:attachment; filename*=\"utf8''".$filename.'"');      }else{          header('content-disposition:attachment; filename="'.$filename.'"');      }  

Try

    $user_agent = $_SERVER['Http_User_agent'];      $encode_filename = rawurlencode($filename);     if(preg_match("/MSIE/", $user_agent)){          header('content-disposition:attachment; filename="'.$encode_filename.'"');      }else if(preg_match("/Firefox/", $user_agent)){          header("content-disposition:attachment; filename*=\"utf8''".$filename.'"');      }else{          header('content-disposition:attachment; filename="'.$filename.'"');      }  



Opening and downloading the file seems to be the first text to solve the problem.

1. header ("Content-Disposition: attachment; filename = $ filename"); must be a pure file name without a path
2. the default character set of phpexcel is utf-8. most people use UTF-8, which is a waste of resources, to save program files. This may inevitably have a BOM header.

In fact, Microsoft is very considerate. it only uses dual bytes for non-English systems (UTF-8 Chinese is 3 bytes)
If a person cannot understand double-byte Chinese, he cannot understand 3-byte Chinese! So what do you call globalization?

1. header ("Content-Disposition: attachment; filename = $ filename"); must be a pure file name without a path
2. the default character set of phpexcel is utf-8. most people use UTF-8, which is a waste of resources, to save program files. This may inevitably have a BOM header.


Solved. thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.