PHP Custom APK installation package Instance _php tips

Source: Internet
Author: User
Tags php ziparchive ziparchive

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.

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.