[英]Return downloadable file in PHP to Internet Explorer with JavaScript
I have a PHP web application in which users can click a button to download an XML file generated on the fly. 我有一个PHP Web应用程序,用户可以单击一个按钮来下载动态生成的XML文件。 It has worked well for a long time, but suddenly I am getting bug reports from a single Internet Explorer user (I only have a screenshot showing the bug). 长期以来,它一直运行良好,但是突然我从一个Internet Explorer用户那里得到了错误报告(我只有一个截图显示该错误)。 I need your help to figure out possible causes. 我需要您的帮助以找出可能的原因。
First, the button click in the web GUI is handled with jQuery which has a JavaScript window.location
statement: 首先,使用具有JavaScript window.location
语句的jQuery处理Web GUI中的按钮单击:
$("#generate-button").click(function() {
...
window.location = "generateXml.phtml";
}
generateXml.phtml
is PHP which creates an XML string which is returned: generateXml.phtml
是PHP,它创建返回的XML字符串:
header('Content-Type: application/xml');
header('Content-Disposition: attachment; filename=xmlFile.xml');
echo $xmlString;
Up until now, users have always been prompted whether to open or save the xmlFile.xml
(which is correct). 到目前为止,总是提示用户打开还是保存xmlFile.xml
(正确)。 Now however, a user of Internet Explorer (version unknown but it appears to be IE10) is prompted whether to open or save generateXml_phtml
: 但是,现在,提示Internet Explorer用户(未知版本,但似乎是IE10)打开还是保存generateXml_phtml
:
Note that IE has replaced the .
请注意,IE已取代.
(dot) with _
(underscore). (点)和_
(下划线)。 It seems the PHP server code in generateXml.phtml
is not even executed. 似乎generateXml.phtml
的PHP服务器代码甚至没有执行。
Do you have any ideas? 你有什么想法? I cannot replicate the bug using IE on my own system. 我无法在自己的系统上使用IE复制错误。
Can you give a direct link to the problem? 您可以直接链接到该问题吗? Try change the extenssion to .php its weird if the file ins´t being processed the web server should only give you a executed code not the raw code, maybe is something wrong with .phtml extenssion... 如果未在Web服务器上处理文件,则仅将扩展名更改为.php,如果只给您一个已执行的代码而不是原始代码,.phtml扩展名可能有问题...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.