繁体   English   中英

Android默认浏览器不会从PC本地主机下载.txt文件

[英]Android default browser doesn't download a .txt file from PC localhost

我在Wamp Server上运行的PHP上编写了一个脚本,该脚本强制下载.txt文件。 该脚本如下所示:

header("Content-Type: application/octet-stream");

$newfile = "data.txt";
header("Content-Disposition: attachment; filename=" . urlencode($newfile));   
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");            
header("Content-Length: " . filesize($newfile));
flush(); // this doesn't really matter.
$fp = fopen($newfile, "r");
while (!feof($fp))
{
    echo fread($fp, 65536);
    flush(); // this is essential for large downloads
} 
fclose($fp);

该代码运行良好。

但是问题是,我已经将我的Android设备连接到PC,并且能够使用任何其他浏览器下载此文件,但不能使用Android默认Web浏览器下载该文件。

有人知道为什么默认浏览器下载失败吗? 但是可以从其他Android平台下载吗?

出于某种原因,Android浏览器对HTTP标头确实很挑剔。

该页面将为您提供有关此问题的一些见解: http : //www.digiblog.de/2011/04/android-and-the-download-file-headers/

引用页面的一部分,如果您使用此行代码,则可能行不通。

Content-Type: application/force-download

该页面还为您提供了一些可能的解决方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM