The example of this article describes the PHP custom APK installation package method, share for everyone to reference. The implementation methods are as follows:
As we all know, the APK format installation file is an Android Smart system installation file, let's take a look at a PHP implementation of a custom APK installation package instance.
First, the demand:
Need to implement a product to recommend a friend installation activities, each member download their own exclusive installation package (which records the members of the relevant information).
Second, train of thought:
after understanding, found that the APK installation package is only a zip of a vest, the use of PHP Ziparchive class can operate on the file.
Third, the implementation code:
Copy Code code as follows:
source files
$apk = "gb.apk";
Generate Temporary files
$file = Tempnam ("tmp", "zip");
Copying files
if (False===file_put_contents ($file, file_get_contents ($apk)) {
Exit (' Copy faild! ');
}
Open temporary file
$zip = new Ziparchive ();
$zip->open ($file);
Add files
Because the APK limit can only modify files in this directory, it will be reported as invalid APK package
$zip->addfromstring (' Meta-inf/extends.json ', Json_encode (Array (' Author ' => ' Deeka '));
Close zip
$zip->close ();
Download files
Header ("Content-type:application/zip");
Header ("Content-length:"). FileSize ($file));
Header ("content-disposition:attachment; Filename=\ "{$apk}\");
Output binary Stream
ReadFile ($file);
Delete temporary files
Unlink ($file);
I hope this article will help you with your PHP program design.