我有一个 PHP 脚本,可让您下载媒体文件。当我通过使用 Android 操作系统的 URL 访问来运行此脚本时,我可以在 apachelog 中看到 2 个命中:
192.168.xxx.xx - - [31/May/2012:15:30:57 +0100] "GET /myScript.php?myParams=myValues HTTP/1.1" 200 409632 "http://myReferer" "Mozilla/5.0 (Linux; U; Android 2.1-update1; fr-fr; HTC Desire 1.19.161.5 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17"
192.168.xxx.xx - - [31/May/2012:15:30:57 +0100] "GET /myScript.php?myParams=myValues HTTP/1.1" 200 409632 "http://myReferer" "Mozilla/5.0 (Linux; U; Android 2.1-update1; fr-fr; HTC Desire 1.19.161.5 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17"
仅当我更改 http 标头“Content-Disposition”或“Content-Type”以使下载有效时,它才会出现两次,而且我认为由于两次点击,下载实际上无法在 Android 手机上运行。但这是我真正的问题:如果我不更改这些标题,当然没有下载!但我只能在我的 apache 访问日志上看到一次命中。
我尝试修改其他标头(Pragma:public,Expires:0,Cache-Control:Public,Content-Transfer-Encoding:binary,Content-Length 等)并且只再次点击一次。它只为上面提到的两个标题发送 2 次点击。
更多信息:
PHP version 5.2.4
Apache version 2.2
Tested with Android 2.2, 2.3.4, 4.0.x
谢谢,如果你知道为什么并解释我,或者只是告诉我如何让我的下载工作。我从上周开始就在这。当然,我用谷歌搜索了它,只有以前版本的 apache 日志的旧错误,没有像我现在这样的东西。
PHP代码:
<?php
//$path is the absolute path of the file I want to download (dl)
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: " . getFileMIME($path)); //return "audio/mpeg" since I want to dl *.mp3
header('Content-Disposition: attachment; filename="' . $filename . '";'); //basename of my file
header("Content-Transfer-Encoding: binary");
header('Content-Length: ' . filesize($path));
readfile($path);
?>
编辑:我找到原因:Android 像 Netscape 几年前所做的那样发送预取...
While pre-fetching of content is a great feature for most consumers, it does have its share of disadvantages.
If you have a tight data cap, the last thing you want is your browser to waste your bandwidth by loading pages you might not even want to visit.
It will also create headaches for webmasters by registering fake hits that will increase bandwidth and server resource consumption, besides messing up analytics.
Netscape had earlier experimented with pre-fetching, but it allowed the webmasters to be in control.
Source : http://techie-buzz.com/browsers/chrome-17-changes-review.html
不知道如何绕过那个愚蠢的功能