Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unreadble code happens when saved file name having chinese characteers. #1

Open
jiji262 opened this issue Aug 27, 2012 · 1 comment
Assignees

Comments

@jiji262
Copy link

jiji262 commented Aug 27, 2012

The solution is here:

    private function set_headers() {
        $ua = $_SERVER["HTTP_USER_AGENT"];
        $filename = $this->filename . ".xls";
        $encoded_filename = urlencode($filename);
        $encoded_filename = str_replace("+", "%20", $encoded_filename);     

        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        //header("Content-Type: application/vnd.ms-excel;charset=UTF-8");
        header("Content-Type: application/download");;
        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-Transfer-Encoding: binary ");
    }

此代码用于解决保存文件名为中文的时候在IE下出现乱码的问题。

@ghost ghost assigned JOakley77 Aug 27, 2012
@jiji262
Copy link
Author

jiji262 commented Sep 21, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants