PHP solves the problem of garbled Chinese names of files uploaded by browsers-compatible with most browsers

Source: Internet
Author: User
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 ;}
?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.