Reputation: 31
I am trying to download an Android APK file that is output by a php page. Downloading is success, But parsing package problem occur when try to install the apk file. Actually, access the filepath(/var/www/xxx/HelloWorldTest.apk) directly, this method installed completely.(no problem.) But I want to use the method that via the php source.
I have Android app on my server and also have php code like:
<?php
$path = "/var/www/xxx/";
$filename="HelloWorldTest.apk";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: application/vnd.android.package-archive");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($path . $filename));
readfile($path . $filename);
?>
Have HelloWorldTest(Android app) Manifest like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworldtest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.helloworldtest.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
My setup: CentOS release 6.3 (Final),2.6.32-279.5.2.el6.x86_64, PHP 5.3.17 Android table Version:3.2.1 kernel version:2.6.36.3
There is difference of binary dump in using direct access method and using php method result.
direct access(success)
50 4B 03 04 14 00 08 08 08 00 F5 91 76 42 00 00
00 00 00 00 00 00 00 00 00 00 1C 00 04 00 72 65
73 2F 6C 61 79 6F 75 74 2F 61 63 74 69 76 69 74
79 5F 6D 61 69 6E 2E 78 6D 6C FE CA 00 00 6D 91
...
via php(install failed)
0A 0A 50 4B 03 04 14 00 08 08 08 00 F5 91 76 42
00 00 00 00 00 00 00 00 00 00 00 00 1C 00 04 00
72 65 73 2F 6C 61 79 6F 75 74 2F 61 63 74 69 76
69 74 79 5F 6D 61 69 6E 2E 78 6D 6C FE CA 00 00
.....
The problem seems to initial part [0A 0A] was added in binary code.
Upvotes: 3
Views: 2997
Reputation: 411
0A is the hex code for line feed. So you appear to have two line feeds added before the actual content of the file. From reading the docs on readfile, it recommends surrounding the readfile call with the following:
ob_clean();
flush();
readfile($path . $filename);
exit;
Try that and see if you still have the two 0A characters.
Upvotes: 3