PHP export download Excel file is blocked by IE, how to solve? Not with stream output!
Download Excel file is blocked by IE, how to solve?
When the export button is clicked, an Excel file is generated in the background via Ajax, and you want the dialog box to appear directly on the page to save the file.
Either through the JS window.location.href= ", or through the form submitted to the new page is not, the background through the flow of output, are blocked by IE;
May I ask who has a solution?
PHP Code
$file _name= "Test.xls";
$file _path= ". /data/down/2011/03/21/";
$file _name = UrlDecode ($file _name);
// .. /isn't allowed in the file name
if (!ereg ("(\.\.\/)", $file _name))
{
Does the file exist?
if (file_exists ($file _path. $file _name))
{
$fp = @fopen ($file _path. $file _name, "R");
Prompt the user to download the new torrent file.
Header ("expires:0");
Header ("Pragma:public");
Header ("cache-control:must-revalidate,post-check=0,pre-check=0");
Header ("Cache-control:public");
Header ("Content-type:application/octet-stream");
if (Strstr ($_server["Http_user_agent"], "MSIE")) {
Header ("Content-disposition:attachment;filename=". UrlEncode ($file _name));
}else{
Header ("Content-disposition:attachment;filename=". $file _name);
}
Header ("Content-transfer-encoding:binary");
Header ("Content-length:". @filesize ($file _path. $file _name));
@fpassthru ($FP);
@fclose ($FP);
}
Exit ();
}
------Solution--------------------
Then I'll just pick up the points.
------Solution--------------------