php导出下载excel文件被ie阻止,怎么解决?用流输出也不行!
下载excel文件被ie阻止,怎么解决?
当点击导出按钮时,通过ajax在后台生成一个excel文件,想直接在页面上弹出文件是否保存的对话框,
无论是通过js的window.location.href='';还是 通过form 提交到新页面都不行,后台通过流方式输出,都被ie阻止;
请问谁有办法解决?
php code
$file_name=test.xls;
$file_path=../data/down/2011/03/21/;
$file_name = urldecode($file_name);
// ../ is not 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();
}
------解决方案--------------------
那我就白捡分了 哈哈
------解决方案--------------------