本文实例讲述了php自定义apk安装包的方法,分享给大家供大家参考。具体实现方法如下:
<?php // 源文件 $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); // 添加文件 // 由于apk限定只能修改此目录内的文件,否则会报无效apk包 $zip->addFromString('META-INF/extends.json', json_encode(array('author'=>'deeka'))); // 关闭zip $zip->close(); // 下载文件 header("Content-Type: application/zip"); header("Content-Length: " . filesize($file)); header("Content-Disposition: attachment; filename=\"{$apk}\""); // 输出二进制流 readfile($file); // 删除临时文件 unlink($file); ?>
原文地址:http://blog.csdn.net/phpfenghuo/article/details/45198537