0

The code below works fine on desktop browsers (Chrome, FF), but when executed from a Android mobile (HTC Evo, Galaxy S) device the file is downloaded but empty. I've added the following line to my .htaccess file...

AddType application/vnd.android.package-archive .apk

... and the download works as expected if I link directly to the .apk from a HTML anchor.

I need to provide the download via a PHP script though so that I can update database records. The following PHP method even works as expected on a blackberry device:

public function download($file)
{
    if (!is_readable($file)) {
        return false;
    }
    header('Content-Type: application/vnd.android.package-archive');
    header('Content-Disposition: attachment; filename="test.apk"');
    header('Content-length: ' . filesize($file));
    readfile($file);
    return true;
}
jondbaker
  • 204
  • 1
  • 7

1 Answers1

0

Cheap solution: telnet to the server, talk HTTP directly, and see what the difference in headers is between downloading from your PHP script vs downloading from the server.

You could also look into things like just redirecting your users to the file, or if you want to get sophisticated, X-sendfile.

You could also look at the answers to this question: Fastest Way to Serve a File Using PHP

Community
  • 1
  • 1
Jords
  • 1,855
  • 3
  • 18
  • 28
  • I'm going to have to look in to how to telnet and do what you've described, but I did check the headers of the file with cURL and after a 301 I get a 200 OK and end up at the .apk file. Unfortunately, I can't just redirect users to the file, because I need to keep it protected. Also complicating the situation is the fact that I'm working on a grid-service and don't have much freedom via SSH (I'm jailed in...). I just can't wrap my head around why it works in each browser/device combination except Android. – jondbaker Aug 02 '11 at 15:25
  • It'll be something strange with the headers etc - That's why I suggest looking at the difference with telnet. Things like X-sendfile keep the file protected, there are some other methods also. – Jords Aug 05 '11 at 11:10
  • Thanks for the responses. The problem exists only when using the default Android browser (installing FF and Opera remedies the problem), but unfortunately the default browser is required for the project flow. I found this article http://forum.xda-developers.com/archive/index.php/t-972708.html that suggests that the default browser will simply not allow .APK downloads without installing a third-party app (Astro File Manager worked for me) to override the default browser filters. In the end, the client opted to just allow the file to live in a public folder so I could redirect users to it. – jondbaker Aug 11 '11 at 18:02