PHP读取exe软件版本号

180it 2020-02-19 AM 2643℃ 0条
/**
 * PHP 读取 exe\dll 文件版本号
 * 
 * @param  $filename 目标文件
 * @return 读取到的版本号
 */
function getFileVersion($filename)
{
    $fileversion = '';
    $fpFile = @fopen($filename, "rb");
    $strFileContent = @fread($fpFile, filesize($filename));
    fclose($fpFile);
    if($strFileContent)
    {
        $strTagBefore = 'F\0i\0l\0e\0V\0e\0r\0s\0i\0o\0n\0\0\0\0\0';        // 如果使用这行,读取的是 FileVersion
        // $strTagBefore = 'P\0r\0o\0d\0u\0c\0t\0V\0e\0r\0s\0i\0o\0n\0\0';    // 如果使用这行,读取的是 ProductVersion
        $strTagAfter = '\0\0';
        if (preg_match("/$strTagBefore(.*?)$strTagAfter/", $strFileContent, $arrMatches))
        {
            if(count($arrMatches) == 2) 
            {
                $fileversion = str_replace("\0", '', $arrMatches[1]);
            }
        }
    }
    return $fileversion;
}
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

PHP读取exe软件版本号