In this case, why cannot the file download be implemented ;? Php $ rootD: wampwww create a folder; if (is_dir ($ root) {& nbsp; $ openHandleopendir ($ root); & nbsp; & nbsp; while (false! ($ Filereaddir ($ openHandle) & nbsp; why cannot I download files?
$ Root = "D:/wamp/www/New Folder /";
If (is_dir ($ root ))
{
$ OpenHandle = opendir ($ root );
While (false! ==( $ File = readdir ($ openHandle )))
{
If (! Is_dir ($ root. $ file ))
{
Echo "". $ file ."
";
Echo "$ root $ file
";
}
}
Closedir ($ openHandle );
}
Else
{
Echo "the folder does not exist ";
}
?>
Why can't this code be used to download files? the Sogou browser has tried IE.
------ Solution --------------------
Download with header
------ Solution --------------------
I have helped you renew it.
$ Root = "D:/ghost /";
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 );
}
------ Solution --------------------
File_put_contents ('Download/excel.csv ', $ str );
Header ("location: download/excel.csv"); // let the computer automatically pop up the download dialog box