PHP export download Excel file is blocked by IE, how to solve? Not with the stream output either.

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