Demand:
Suddenly received the boss's needs, to the product to recommend a friend installation activities, each member download their own exclusive installation package (which records the members of the relevant information).
Ideas:
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.
Implementation code:
The code is as follows |
Copy Code |
///source files $ apk = "gb.apk"; //Generate temporary files $file = Tempnam ("tmp", "zip"); //Copy file if (false===file_put_contents $file, File_ Get_contents ($apk)) { exit (' Copy faild! '); } //Open temporary file $zip = new ziparchive (); $zip->open ($file); //Add File /////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 file 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); |