.txt ファイルのダウンロードを強制するスクリプトを、Wamp サーバーで実行する PHP で作成しました。スクリプトは次のようになります。
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で他のからダウンロードできますか?