PHP solve the problem of garbled Chinese names of the file downloaded by the browser-compatible with most browsers functionsendFile ($ serverPath, $ filename, $ charsetUTF-8, $ mimeTypeapplicationoctet-stream) {file name garbled problem if (preg_match (MSIE, $ _ ser php solves the problem of garbled Chinese names of downloaded files in browsers-compatible with most browsers
Function sendFile ($ serverPath, $ filename, $ charset = 'utf-8', $ mimeType = 'application/octet-stream ') {// if (preg_match ("/MSIE/", $ _ SERVER ["HTTP_USER_AGENT"]) {$ filename = urlencode ($ filename ); $ filename = str_replace ("+", "% 20", $ filename); // replace the space $ attachmentHeader = "Content-Disposition: attachment; filename = \ "{$ filename} \"; charset = {$ charset} ";} else if (preg_match ("/Firefox /", $ _ SERVER ["HTTP_USER_AGENT"]) {$ attachmentHeader = 'content-Disposition: attachment; filename * = "utf8 \'\''. $ filename. '"';} else {$ attachmentHeader =" Content-Disposition: attachment; filename = \ "{$ filename} \"; charset = {$ charset }";} $ filesize = filesize ($ serverPath); // 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: {$ mimeType} "); header ($ attachmentHeader); header ('pragma: cache'); header ('cache-Control: public, must-revalidate, max-age = 0'); header ("Content-Length: {$ filesize}"); readfile ($ serverPath); exit ;}
?