1

Androidでファイルをダウンロードしたいので、次の関数を使用してphpでファイルをストリーミングします

function stream($fileName,$fileSize,$fName){
        //header("Pragma:public");
        //header("Expires:0");
        //header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        //header("Cache-Control:private",false);
        header("Content-Disposition:attachment;filename=\"".$fName."\";");
        header("Content-Type:application/octet-stream");  
        header("Content-Transfer-Encoding:binary");
        header("Content-Length:".$fileSize);
        readfile($fileName);
}

ただし、ダウンロードは Android デバイスでは機能しません。私のコンピュータでは、それは問題ではありません。http://www.digiblog.de/2011/04/android-and-the-download-file-headers/で既に解決策を見つけましたが、ここでは役に立ちませんでした。

4

1 に答える 1

2

あなたが引用した私のブログ投稿で述べたように、 Android デバイスでのダウンロードの成功は、コードを読んでも分からない複数の要因に依存します。

  • $fileName には大文字の拡張子が含まれている必要があります。

  • The pure URL that you call to download must contain all information needed for the download to start. No POST parameters may be involved, they will not be forwarded to the Android Download Manager and thus the download will fail. GET parameters (query string) are ok.

  • Also you did not obey the blog posting in all details:
    There is a semicolon after your Content-Disposition header which is fatal.

I also recommend to start with the Content-Type and Content-Disposition headers ONLY. When you got it working on Android, you can still add any other headers that you want to send. But do not forget to re-test on Android (multiple versions if possible) when you are complete. Android is really picky about some of those headers (or should I say "bitchy"?).

If all of this does not help you will have to provide some more information about your case. What exactly happens when you try it? What URL do you call. What are the parameters passed to your function?

于 2013-11-20T08:03:33.510 に答える