使用PHP下载APK文件 [英] Download APK file using PHP
问题描述
我想使用Chrome使用PHP在我的电脑浏览器下载一个Android APK文件。
I am trying to download an android APK file using php in my PC browser using Chrome.
我的应用程序位于服务器的特定路径。如果我手动从FTP服务器传输文件到我的Android手机安装它完美。但是,当我下载使用PHP和下载的文件传送到移动和安装时,它抛出的有,在分析软件包是一个问题
My app is located in a particular path in the server. If I manually FTP the file from server and transfer to my android mobile it installed perfect. But when I downloaded using PHP and transfer the downloaded file to Mobile and while installing it throws 'there was a problem while parsing the package'.
下面是我的PHP code我用它来下载
Here is my PHP code I use to download
header('Content-Type: application/vnd.android.package-archive');
header('Content-Disposition: attachment; filename="' . $file_name . '"');
readfile($file_path);
return true;
FYI ...
fyi...
$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文件。
I found one observation while trying to open the APK file using 7-zip.
当我打开使用的7-Zip,它抛出一个错误的文件无法打开文件XXX作为存档
When I open the file using 7-zip it throws an error 'Cannot open the file xxx as archive'
在我添加了下面的PHP code
After I added the below PHP code
header("Content-length: " . filesize($file_path));
现在,当我打开使用文件7-压缩它打开该文件,但下载的文件的大小比原始文件越大。而当我移动了同样的错误打开此文件的有,在分析软件包是一个问题
Now when I open the file using 7-zip it opens the file but the size of the downloaded file is greater than the original file. And when I open this file in mobile the same error 'there was a problem while parsing the package'
要砍我长话短说,我试图从服务器下载APK文件使用PHP为localhost和我能够使它发挥作用。
To cut my long story short, I am trying to download an APK file from server to localhost using PHP and I'm able to make it work.
推荐答案
我设法让加入它的工作的 ob_end_flush()函数
I managed to make it work by adding ob_end_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;
这篇关于使用PHP下载APK文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!