(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.