PHP-为android设备动态生成文件

PHP-为android设备动态生成文件,php,android,header,on-the-fly,Php,Android,Header,On The Fly,我在这里读了一些答案,但我似乎无法使我的php脚本正常工作。 我从表单生成一个文本或csv文件(取决于用户选择的内容),然后将其提交回同一页面。 该脚本在我的桌面上的Chrome、IE、Mozilla上运行良好,但当我在Android上尝试股票浏览器时,我会得到一个包含脚本源代码的attachment.html文件。 如果我尝试使用下一个浏览器,我会得到一个文件名正确的文件,但里面也是我脚本的来源 我已经阅读了下面的链接,但我不能让它工作 我的http头如下所示 header("Content

我在这里读了一些答案,但我似乎无法使我的php脚本正常工作。 我从表单生成一个文本或csv文件(取决于用户选择的内容),然后将其提交回同一页面。 该脚本在我的桌面上的Chrome、IE、Mozilla上运行良好,但当我在Android上尝试股票浏览器时,我会得到一个包含脚本源代码的attachment.html文件。 如果我尝试使用下一个浏览器,我会得到一个文件名正确的文件,但里面也是我脚本的来源

我已经阅读了下面的链接,但我不能让它工作

我的http头如下所示

header("Content-Description: File Transfer");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"" . basename($FileName) . "\"");
header("Content-Length: " . filesize($FileName));
header("Content-Transfer-Encoding: binary");
header("Expires: 0");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
header("Pragma: no-cache");
header("Connection: close");
print $Content;
exit();
-----更新1----

我编写了以下代码来进行测试

<?php
$get = $_GET['get'];
if ($get == 1) {
$content = 'This is a line of text!';
$filename = 'superfile';
header("Content-Description: File Transfer");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"" . basename($filename) . ".TXT\"");
header("Content-Transfer-Encoding: binary");
header("Expires: 0");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
header("Pragma: no-cache");
header("Connection: close");
echo $content;
exit;

}
echo '<html>
<head>
    <title>Test</title>
</head>
<body>
    <form method="get" action="index.php"
    <label>Get</label>
    <input type="text" name="get"/>
    <input type="submit" name="ok" value="Send"/>
    </form>
</body>
</html>';
?>

当我使用get方法发送表单时,一切正常,当我使用post时,我得到了您看到的html源代码,这与我的原始脚本的问题相同

-----更新2-----

Okkkkk,现在有更多的信息,我认为这与Android bug有关,请查看以下链接


在等待解决这个问题的建议时,我需要一个方法来发布帖子,因为我传递了太多变量,我不想在地址栏上有一个丑陋的url。

好吧,我不想做太多实验,所以我得到了用户代理,并将我的帖子表单改为get。这不是一个很好的解决方案,但工作已经完成。

如果您从手机上浏览页面,您将获得实际的PHP代码?尝试时没有插入括号,但不起作用。表单使用POST方法,并提交回同一页面。url是这样的。不,我正确地看到了表单,我提交了表单,接受了下载,但是文件不是我从桌面浏览器中得到的。我尝试了几种浏览器,Chrome、Mozilla和Opera,效果很好。使用stock android browser、next browser和dolpin,我会得到一个包含页面源(而不是脚本源)的文件。