PHP resolution browser Upload file Chinese name garbled related issues-compatible with most browsers

Source: Internet
Author: User
PHP solution Browser Download file Chinese name garbled problem--compatible with most browsers
function SendFile ($serverPath, $filename, $charset = ' UTF-8 ', $mimeType = ' Application/octet-stream ') {//filename garbled problem if (preg _match ("/msie/", $_server["Http_user_agent"])) {$filename = UrlEncode ($filename); $filename = Str_replace ("+", "%20", $ filename);//Replace 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;} 
?
  • 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.