Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP下载APK文件_Php_Android_Apk - Fatal编程技术网

使用PHP下载APK文件

使用PHP下载APK文件,php,android,apk,Php,Android,Apk,我正试图在使用Chrome浏览器的PC浏览器中使用php下载android APK文件 我的应用程序位于服务器中的特定路径中。如果我手动将文件从服务器FTP传输到我的android手机上,它会安装得非常完美。但是,当我使用PHP下载并将下载的文件传输到Mobile时,安装时抛出了“解析包时出现问题” 这是我用来下载的PHP代码 header('Content-Type: application/vnd.android.package-archive'); header('Content-Disp

我正试图在使用Chrome浏览器的PC浏览器中使用php下载android APK文件

我的应用程序位于服务器中的特定路径中。如果我手动将文件从服务器FTP传输到我的android手机上,它会安装得非常完美。但是,当我使用PHP下载并将下载的文件传输到Mobile时,安装时抛出了“解析包时出现问题”

这是我用来下载的PHP代码

header('Content-Type: application/vnd.android.package-archive');
header('Content-Disposition: attachment; filename="' . $file_name . '"');
readfile($file_path);
return true;
仅供参考

$file_name is the apk file file 'myfile.apk'
$file_path is the full absolute path of the file in server ('d:\abcd\xyz\xampp\htdocs\apkstore\myfile.apk')
我在尝试使用7-zip打开APK文件时发现了一个观察结果

当我使用7-zip打开文件时,它会抛出一个错误“无法将文件xxx作为存档打开”

在我添加了下面的PHP代码之后

header("Content-length: " . filesize($file_path));
现在,当我使用7-zip打开文件时,它会打开文件,但下载文件的大小大于原始文件。当我在mobile中打开此文件时,出现了相同的错误“解析包时出现问题”


长话短说,我正在尝试使用PHP将APK文件从服务器下载到本地主机,并且我能够使其工作。

我通过添加ob\u end\u flush()使其工作。

header('Content-Type: application/vnd.android.package-archive');
header("Content-length: " . filesize($file_path));
header('Content-Disposition: attachment; filename="' . $file_name . '"');
ob_end_flush();
readfile($file_path);
return true;