處理導出文件文件名的辦法

處理文件名的大體辦法 php

        $time = date('Y_m_d', time());
        $file_type = "vnd.ms-excel"; // excel表格固定寫法
        $file_ending = "xls"; // excel表的後綴名
        header("Content-Type:application/{$file_type}; charset=gbk");
        $filename = '花名冊總信息'.$time.'.'.$file_ending;     

        $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 . '"');
        }
相關文章
相關標籤/搜索