(High score) why cannot this code be downloaded?

Source: Internet
Author: User
(High score) why does this code fail to provide a high score for downloading files:
Why can't I download files using this code? I tried it in LINUX and WINDOWS. Run OB_start () in WINDOWS and the program will not run.
$ Root = "D:/wamp/www/panjinli/downloadsouce ";
If (is_dir ($ root ))
{
$ OpenHandle = opendir ($ root );
While (false! ==( $ File = readdir ($ openHandle )))
{
If (! Is_dir ($ root. $ file ))
{
Echo "". $ root. $ file ."
";
}
}
Closedir ($ openHandle );
} Else
{
Echo "the folder does not exist ";
}

$ Do = (isset ($ _ REQUEST ['do '])? Addslashes ($ _ REQUEST ['do ']): '';
If ($ do = 'low ')
{
$ File = (isset ($ _ REQUEST ['file'])? Addslashes ($ _ REQUEST ['file']): '';
$ Path = (isset ($ _ REQUEST ['path'])? Addslashes ($ _ REQUEST ['path']): '';

OB_start ();
Function DownLoad ($ info, $ file)
{
OB_Clean ();
If (! File_exists ($ info ))
{
Exit ('Error: '. _ LINE _.', '. basename (_ FILE __).'! ');
}

$ Info = file_get_contents ($ info );

Header ('content-Transfer-Encoding: binary ');
Header ('content-Type: application/force-download; name = "'. $ file .'"');
Header ('content-Disposition: attachment; filename = '. $ file .'');
Header ('cache-control: private ');
Header ('pragma: no-cache ');
Header ('expires: 0 ');
Echo $ info;
Die ();
}
DownLoad ($ path. $ file, $ file );
}
?>


Reply to discussion (solution)

Why are there no people?


DownLoad ($ path. $ file, $ file );

Change
DownLoad ($ path. '/'. $ file, $ file );


DownLoad ($ path. $ file, $ file );

Change
DownLoad ($ path. '/'. $ file, $ file); I tried it.

I changed this. the local test is OK... Set the encoding.

I changed this. the local test is OK... Set the encoding to see if you are in LINUX or windows.
How to set encoding?

I changed this. the local test is OK... Set the encoding to see how it helps me solve the problem and I will give it to you.

I changed this. the local test is OK... Set the encoding to see if the encoding is correct. the "+" number in the file name is changed to blank.

Header ('content-Disposition: attachment; filename = '. urlencode ($ file ).'');

If (! Is_dir ($ root. $ file ))
{

Echo "". $ root. $ file ."
";

}
}
You can also encode the url parameter file name in the link.

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.