Php exports and downloads Excel files are blocked by IE. how can this problem be solved? Neither can I use stream output!

Source: Internet
Author: User
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!

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.