Re: Get a file's version in PHP



Another option, without using COM, would be to open the binary file and search for the pattern F\0i\0l\0e\0V\0e\0r\0s\0i\0o\0n\0\0\0\0\0
The version is right behind that string:


$strFile = "c:\\my.exe";
$fpFile  = fopen($strFile, "rb");
$strFileContent = fread($fpFile, filesize($strFile));
fclose($fpFile);

$strTagBefore = 'F\0i\0l\0e\0V\0e\0r\0s\0i\0o\0n\0\0\0\0\0';
$strTagAfter = '\0\0';
if (preg_match("/$strTagBefore(.*?)$strTagAfter/", $strFileContent, $arrMatches))
{
print_r($arrMatches);
}


HTH.
Peter.
--
http://www.phpforums.nl
.



Relevant Pages

  • RE: Searching binary files for patterns?
    ... far all of my search functions are done except one, searching a binary file ... for a certain pattern or a pattern with a wildcard. ...
    (microsoft.public.dotnet.languages.vb)
  • binary grep
    ... pattern in a binary file, then at least output file position (so that ... The pattern could be either fixed bytes or even regular expression, ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Re: Search for byte pattern in a binary file.
    ... "Thomas Weidenfeller" wrote in message ... > Ryan Tan via JavaKB.com wrote: ... His main concern is about finding the byte pattern ...
    (comp.lang.java.programmer)
  • Re: Help me with this!!!
    ... It works perfecly on a txt file but if I open a binary file (.exe,.bin ... This pattern IS in the file (I made it and I double check with an hex ... the file in notepad (or other text editor)? ...
    (comp.lang.python)
  • How to substitute a string with different size
    ... I deal with a mixture of text and binary file. ... pattern in the string and replace it with a new pattern, ... wonder if any one out there knows how to explain it and provide a Ruby ...
    (comp.lang.ruby)