Home Backend Development PHP Tutorial php导出下载Excel文件被IE阻止,如何解决?用流输出也不行

php导出下载Excel文件被IE阻止,如何解决?用流输出也不行

Jun 13, 2016 pm 01:33 PM
content file header name quot

php导出下载Excel文件被IE阻止,怎么解决?用流输出也不行!
下载Excel文件被IE阻止,怎么解决? 
当点击导出按钮时,通过AJAX在后台生成一个excel文件,想直接在页面上弹出文件是否保存的对话框,
无论是通过js的window.location.href='';还是 通过form 提交到新页面都不行,后台通过流方式输出,都被IE阻止; 
请问谁有办法解决?

PHP code

1

<br> $file_name="test.xls"; <br> $file_path="../data/down/2011/03/21/"; <br> $file_name = urldecode($file_name); <br>  <br> // ../ is not allowed in the file name <br> if (!ereg("(\.\.\/)", $file_name)) <br> { <br> // Does the file exist? <br>  if (file_exists($file_path . $file_name)) <br>    { <br>        $fp = @fopen( $file_path . $file_name, "r" ); <br>        //Prompt the user to download the new torrent file. <br>      header("Expires: 0" ); <br>       header("Pragma:public" ); <br>        header("Cache-Control:must-revalidate,post-check=0,pre-check=0" ); <br>       header("Cache-Control:public"); <br>      header("Content-Type:application/octet-stream" ); <br>         <br>         if (strstr($_SERVER["HTTP_USER_AGENT"],"MSIE")) { <br>            header("Content-Disposition:attachment;filename=".urlencode($file_name) ); <br>       }else{ <br>           header("Content-Disposition:attachment;filename=".$file_name ); <br>      } <br>        header("Content-transfer-encoding: binary"); <br>         header("Content-length:".@filesize( $file_path . $file_name )); <br>       <br>         @fpassthru( $fp ); <br>       @fclose( $fp ); <br>      } <br>    exit(); <br> }  <br>  <br>

Copy after login





------解决方案--------------------
那我就白捡分了 哈哈
------解决方案--------------------
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hongmeng native application random poetry Hongmeng native application random poetry Feb 19, 2024 pm 01:36 PM

Hongmeng native application random poetry

Use java's File.length() function to get the size of the file Use java's File.length() function to get the size of the file Jul 24, 2023 am 08:36 AM

Use java's File.length() function to get the size of the file

How to convert php blob to file How to convert php blob to file Mar 16, 2023 am 10:47 AM

How to convert php blob to file

What does linux header mean? What does linux header mean? Jul 18, 2023 pm 03:34 PM

What does linux header mean?

How does SpringBoot pass parameters in the Header through Feign calls? How does SpringBoot pass parameters in the Header through Feign calls? May 16, 2023 pm 08:38 PM

How does SpringBoot pass parameters in the Header through Feign calls?

Rename files using java's File.renameTo() function Rename files using java's File.renameTo() function Jul 25, 2023 pm 03:45 PM

Rename files using java's File.renameTo() function

Use java's File.getParentFile() function to get the parent directory of the file Use java's File.getParentFile() function to get the parent directory of the file Jul 27, 2023 am 11:45 AM

Use java's File.getParentFile() function to get the parent directory of the file

Use java's File.getParent() function to get the parent path of the file Use java's File.getParent() function to get the parent path of the file Jul 24, 2023 pm 01:40 PM

Use java's File.getParent() function to get the parent path of the file

See all articles