You do not need to use a database for simple download. the code is as follows, but you cannot download it. please find out the reason. there is no problem with the file path.

Source: Internet
Author: User
You do not need to use a database for simple download. the code is as follows, but you cannot download it. please find out the reason. there is no problem with the file path. & Lt ;? Phpfunctiondown_file ($ file_name, $ file_sub_dir) {// to prevent garbled characters, use the function iconv $ file_name = iconv (& you do not need to use a database for simple download. the code is as follows, however, the file cannot be downloaded. you can find the reason why the file path is okay.

Function down_file ($ file_name, $ file_sub_dir ){



// Use the iconv function to prevent garbled characters
$ File_name = iconv ("UTF-8", "gb2312", $ file_name );

// Absolute path strength
$ File_path = $ _ SERVER ['document _ root']. $ file_sub_dir. $ file_name;

// Open the file
If (! File_exists ($ file_path )){
Echo "the file does not exist ";
Return;

}
$ Fp = fopen ($ file_path, "r ");

// Obtain the file size
$ File_size = filesize ($ file_path );


// The download size is limited to 10 MB.
If ($ file_size> 10*1021*1024 ){

Echo"

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.