奥利给!
前端
<a href="http://test.domin.com/download.php?act=getTemplate" target="_blank" download="导入模板">
PHP 后端
$out_filename = "导入模板"; // 文件名称
$tmpFilePath = APP_ROOT . PROJECT_PATH ."/static/clue/$out_filename.xls";
$fileName = $out_filename . '.xls';
$suffix = '.xls';
$ua = $_SERVER["HTTP_USER_AGENT"];
ob_end_clean();
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
if ($suffix == '.xlsx') {
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
} else {
header('Content-Type: application/vnd.ms-excel');
}
if (preg_match("/MSIE/", $ua) || preg_match('/edge/', $ua) || preg_match('/edg/', $ua)) {
$encoded_filename = urlencode($fileName);
$encoded_filename = str_replace("+", "%20", $encoded_filename);
header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');
} else if (preg_match("/Firefox/", $ua)) {
header('Content-Disposition: attachment; filename*="utf8\'\'' . $fileName . '"');
} else if (preg_match("/Safari/", $ua) || preg_match("/WeChat/", $ua)) {
$attachment = 'attachment; filename*=utf-8\'\'' . rawurlencode($fileName);
header('Content-Disposition: ' . $attachment);
} else {
header('Content-Disposition: attachment; filename="' . $fileName . '"');
}
header("Content-Transfer-Encoding: binary");
header("Pragma: no-cache");
echo file_get_contents($tmpFilePath);
die;