When uploading the jar mobile game client, some mobile phones, such as some Samsung models, can only install Jad files, so you need to obtain a function to automatically generate Jad Based on the JAR file during background upload. Generally in the jar file package, there will be a game information file, usually in the META-INF/manifest. in MF, we only need to read the content of this file, and then add some other information to generate the JAD file. Here, the PHP zip extension is used to read the contents of the JAR file.
1. install PHP zip Extension
Wget http://pecl.php.net/get/zip-1.10.2.tgz
Tar zxvf zip-1.10.2.tgz
CDS zip-1.10.2
/Opt/php528fpm/bin/phpize
./Configure -- With-PHP-Config =/opt/php528fpm/bin/PHP-config
Make
Make install
CP/opt/php528fpm/lib/PHP/extensions/no-debug-non-zts-20060613/zip. So/opt/php528fpm/EXT/
VI/opt/php528fpm/lib/PHP. ini
Extension = zip. So // Add zip. So Extension
/Opt/php528fpm/sbin/PHP-FPM restart // restart PHP
Ii. Read the file content in jar to generate Jad
$jar_file = "test.jar";$jar_content = zip_open($jar_file);if(!empty($jar_content)){$jar_size = filesize($jar_file);while ($zip_entry = zip_read($zip)) {if (zip_entry_name($zip_entry) == "META-INF/") {if (zip_entry_open($zip, $zip_entry, "r")) {$jad_content = "MIDlet-Jar-Size: $jar_size/rMIDlet-Jar-URL: $jar_file/r/n";$jad_content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));$jad_file = str_replace('jar','jad',$jar_file);$handle = fopen($jad_file, "w");fwrite($handle, $jad_content);zip_entry_close($zip_entry);}}}}