Php custom apk installation package instance

Source: Internet
Author: User
Tags php ziparchive ziparchive
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.