This article mainly introduces the php user-defined apk installation package method. it is very useful to implement this function through the ZipArchive class, for more information about how to use the php custom apk installation package, see the following example. The specific implementation method is as follows:
As we all know, the apk installation file is the installation file of the android smart system. let's look at an example of using php to implement a custom apk installation package.
I. requirements:
You need to perform a recommended friend installation activity for the product. each member downloads its own exclusive installation package (which records member information ).
II. ideas:
After learning about it, we found that the apk installation package was originally a zip vest. you can use the php ZipArchive class to operate the file.
III. implementation code:
The code is as follows:
// Source file
$ Apk = "gb.apk ";
// Generate a temporary file
$ File = tempnam ("tmp", "zip ");
// Copy an object
If (false === file_put_contents ($ file, file_get_contents ($ apk ))){
Exit ('copy faild! ');
}
// Open a temporary file
$ Zip = new ZipArchive ();
$ Zip-> open ($ file );
// Add a file
// Only files in this directory can be modified due to apk limitation. Otherwise, an invalid apk package will be reported.
$ Zip-> addFromString ('meta-INF/extends. json', json_encode (array ('author' => 'demo ')));
// Close the zip file
$ Zip-> close ();
// Download an object
Header ("Content-Type: application/zip ");
Header ("Content-Length:". filesize ($ file ));
Header ("Content-Disposition: attachment; filename = \" {$ apk }\"");
// Output binary stream
Readfile ($ file );
// Delete a temporary file
Unlink ($ file );
I hope this article will help you with php programming.