PHP automatically generates a JAD file when reading jar Information

Source: Internet
Author: User
Tags zip extension

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);}}}}

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.