Troubleshoot issues with uploading PHP Chinese files

Source: Internet
Author: User
Solve the problem of php Chinese file download

The following function is in PHP to determine whether the download file exists (including Chinese, English, etc.), the absence of the prompt, the presence of the original name on the server to download, of course, you can also customize the name.

First of all, the site directory is as follows:

/

..... down.html

..... Sphinx Technical Exchange. zip

.... Lib

??? ... download.php

?

Of course, if the relative path of the site and the absolute path understanding is familiar with, you can not understand the layout of the directory, directly look at the source program.

?

File name: down.html download page





<title>Download Center</title>





Sphinx Technical Exchange




?

The file name is: download.php processing the Download Program page

Header ("Content-type:text/html;charset=utf-8");
$FN = UrlDecode ($_request[' fn ');? To decode, file name (package extension)
Determine if the download name is original or custom
if (!empty ($_request[' Savefn ')) {
??? $savefn = UrlDecode ($_request[' savefn ');? To decode, the file name that is displayed when downloading (without package extension)
??? $FNARR = Explode ('. ', $FN);
??? $savefn = $savefn. ".". $FNARR [Count ($FNARR)-1];? Convert Utf-8 to GB2312
}else{
??? $savefn = $FN;? The name of the original file name as the download display
}
$FN = Iconv (' UTF-8 ', ' Gb2312//ignore ', $FN);? Convert Utf-8 to GB2312
$fp = '. /'. $fn;? The path of the downloaded file, if changed to $fp = ' http://localhost/'. $fn; There will be problems, preferably with a relative path, directly from the root directory down

if (!is_file ($fp)) {//check if file exists
??? echo "";
??? Exit
} else {
??? $savefn = Iconv (' UTF-8 ', ' Gb2312//ignore ', $savefn);
??? $file = fopen ($fp, "R"); Open File
??? Header ("Content-type:application/octet-stream");
??? Header ("Accept-ranges:bytes");
??? Header ("Accept-length:". FileSize ($FP));
??? Header ("content-disposition:attachment; Filename= ". $SAVEFN); #下载时显示的文件名
??? Echo fread ($file, FileSize ($fp));
??? Fclose ($file);
??? 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.