gpt4 book ai didi

php - 在php中下载Android binary(apk),安装apk文件时解析错误包

转载 作者:搜寻专家 更新时间:2023-10-31 21:12:45 26 4
gpt4 key购买 nike

我正在尝试下载由 php 页面输出的 Android APK 文件。下载成功,但尝试安装apk文件时出现解析包问题。其实,直接访问文件路径(/var/www/xxx/HelloWorldTest.apk),这个方法安装完全。(没问题。)但我想使用通过 php 源的方法。

我的服务器上有 Android 应用程序,还有如下 php 代码:

<?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);
?>

让 HelloWorldTest(Android 应用程序) list 如下:

<?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>

我的设置:CentOS 6.3 版(最终版),2.6.32-279.5.2.el6.x86_64,PHP 5.3.17安卓表版本:3.2.1 内核版本:2.6.36.3

binary dump使用direct access方法和使用php方法结果有区别。

直接访问(成功)

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
...

通过 php(安装失败)

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
.....

问题似乎是初始部分 [0A 0A] 是以二进制代码添加的。

最佳答案

0A 是换行的十六进制代码。因此,您似乎在文件的实际内容之前添加了两个换行符。通过阅读 readfile 上的文档,它建议使用以下内容包围 readfile 调用:

ob_clean();
flush();
readfile($path . $filename);
exit;

试试看你是否还有两个 0A 字符。

关于php - 在php中下载Android binary(apk),安装apk文件时解析错误包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15607848/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com