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