在php中检查jar文件是否已损坏?(Check jar file is corrupted or not in php?)

编程入门 行业动态 更新时间:2024-10-21 17:38:29
在php中检查jar文件是否已损坏?(Check jar file is corrupted or not in php?)

我正在使用函数exec()执行jar文件:

但是我需要检查jar文件是否已损坏或使用php函数。

I am executing jar file through php using function exec();

However i need to check whether jar file corrupted or not using php function.

最满意答案

你可以使用zip检查损坏的jar,因为jar文件是一个压缩文件,所以这会给你一个想法:

$myfile = '/my/jar/file.jar'; $zip = new ZipArchive(); $res = $zip->open($myfile, ZipArchive::CHECKCONS); if ($res !== TRUE) { switch($res) { case ZipArchive::ER_NOZIP: die('not a zip archive'); case ZipArchive::ER_INCONS : die('consistency check failed'); case ZipArchive::ER_CRC : die('checksum failed'); default: die('error ' . $res); } }

要使用zip文件,您需要安装php zip扩展

You can check for corrupted jar using zip because the jar file is a zipped file, so this will give you an idea:

$myfile = '/my/jar/file.jar'; $zip = new ZipArchive(); $res = $zip->open($myfile, ZipArchive::CHECKCONS); if ($res !== TRUE) { switch($res) { case ZipArchive::ER_NOZIP: die('not a zip archive'); case ZipArchive::ER_INCONS : die('consistency check failed'); case ZipArchive::ER_CRC : die('checksum failed'); default: die('error ' . $res); } }

For working with zip files you will need to install the php zip extension

更多推荐

jar,php,exec,函数,使用,电脑培训,计算机培训,IT培训"/> <meta name="descriptio

本文发布于:2023-08-06 20:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1455714.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   jar   php   corrupted   file

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!