Php exports and downloads Excel files are blocked by IE. how can this problem be solved? Neither can I use stream output! How can I solve the problem of preventing IE from downloading Excel files?
When you click the export button, AJAX is used to generate an excel file in the background, and you want to directly display the file storage dialog box on the page,
Neither the window. location. href = ''through js, nor the new page submitted through form, nor the output through stream in the background are blocked by IE;
Who can solve this problem?
$file_name="test.xls";$file_path="../data/down/2011/03/21/";$file_name = urldecode($file_name);// ../ is not allowed in the file nameif (!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();}
Reply to discussion (solution)
Solved the front-end js problem ..
$. Ajax ({type: "post", dataType: "html", url: "query. php ", // data: url, cache: false, beforeSend: function({}('{load'}.css (" top ", $ (document ). scrollTop (); $ ('# load '). show ('20140901');}, complete: function () {$ ('# load '). hide ('000000') ;}, success: function (html) {$ ("# tests" ).html (html); // window. location = "test. php "; // A blocking prompt will appear here}, error: function (XMLHttpRequest, textStatus) {alert (" page request error, please contact the system administrator! \ N "+ textStatus) ;}}); window. location =" test. php "; // It is normal to put it in this position!
Then I just split it. haha.
I am so grateful for the two-day tangle and finally solved the problem. In the past, the ajax request callback function could not be used for download requests...
I am so grateful for the two-day tangle and finally solved the problem. In the past, the ajax request callback function could not be used for download requests... Well, how did you solve it?
Thank you for sharing!