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请求回调函数中进行下载请求。。。 额,你是怎么解决的啊?
谢谢分享哦!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio
