处理导出文件文件名的办法

处理文件名的大致办法

        $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 . '"');
        }

你可能感兴趣的:(PHP,File,download)