需求:
突然收到老大的需求,要对产品进行一次推荐好友安装的活动,每个会员下载自己的专属安装包(里面记录会员的相关信息)。
思路:
经过了解,发现apk安装包原来只是zip的一个马甲,使用php的ZipArchive类可以对文件进行操作。
实现代码:
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 
 | $apk    = "gb.apk";
 
 $file   = tempnam("tmp", "zip");
 
 if(false===file_put_contents($file, file_get_contents($apk))){
 exit('copy faild!');
 }
 
 $zip    = new ZipArchive();
 $zip->open($file);
 
 
 $zip->addFromString('META-INF/extends.json', json_encode(array('author'=>'deeka')));
 
 $zip->close();
 
 header("Content-Type: application/zip");
 header("Content-Length: " . filesize($file));
 header("Content-Disposition: attachment; filename=\"{$apk}\"");
 
 readfile($file);
 
 unlink($file);
 
 |