ie导出的excel是php文件,php导出下载Excel文件被IE阻止,怎么解决?用流输出也不行!...

下载Excel文件被IE阻止,怎么解决?

当点击导出按钮时,通过AJAX在后台生成一个excel文件,想直接在页面上弹出文件是否保存的对话框,

无论是通过js的window.location.href='';还是 通过form 提交到新页面都不行,后台通过流方式输出,都被IE阻止;

请问谁有办法解决?

$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();}

回复讨论(解决方案)

解决了,前台js的问题。。$.ajax({type: "post", dataType: "html", url: "query.php",//data:url,cache:false,beforeSend:function(){$('#load').css("top",$(document).scrollTop());$('#load').show('100');},complete :function(){$('#load').hide('100');},success: function(html){ $("#tests").html(html); //window.location = "test.php";//这句话放在此处会出现阻止的提示},error:function(XMLHttpRequest,textStatus ){alert("页面请求错误,请联系系统管理员!\n"+textStatus);}});window.location = "test.php";//放在这个位置就正常了!

那我就白捡分了 哈哈

太感谢了 纠结了2天的问题终于解决了。原来不能在ajax请求回调函数中进行下载请求。。。

太感谢了 纠结了2天的问题终于解决了。原来不能在ajax请求回调函数中进行下载请求。。。 额,你是怎么解决的啊?

谢谢分享哦!

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值