Get a file's version in PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marius III

    #1

    Get a file's version in PHP

    Hi there,

    I want to get the file version of a file in PHP.

    Do somebody have the code for this?

    Thanks alot!


  • Janwillem Borleffs

    #2
    Re: Get a file's version in PHP

    Marius III wrote:[color=blue]
    > Hi there,
    >
    > I want to get the file version of a file in PHP.
    >
    > Do somebody have the code for this?
    >
    > Thanks alot!
    >[/color]

    What do you mean? If you mean the file creation date/last modified date, you
    can use the filectime/filemtime functions.


    JW



    Comment

    • Marius III

      #3
      Re: Get a file's version in PHP

      No, I need to get the FileVersion.
      For example an EXE files version can be: 2.0.0.260 and a newer version of
      this EXE can be 2.0.0.269.


      Thanks alot!


      Comment

      • Sadara

        #4
        Re: Get a file's version in PHP

        Marius III wrote:[color=blue]
        > Hi there,
        >
        > I want to get the file version of a file in PHP.
        >
        > Do somebody have the code for this?
        >
        > Thanks alot![/color]

        which OS are you working on? OpenVMS?

        Comment

        • Janwillem Borleffs

          #5
          Re: Get a file's version in PHP

          Marius III wrote:[color=blue]
          > No, I need to get the FileVersion.
          > For example an EXE files version can be: 2.0.0.260 and a newer
          > version of this EXE can be 2.0.0.269.
          >[/color]

          Since you are mentioning EXE files, I assume that you need this for a
          Windows environment.

          Here, you can use the COM extension (http://www.php.net/com) as follows:

          <?php

          //create FSO instance
          $fso = new COM("Scripting. FileSystemObjec t")
          or die("Could not create Scripting.FileS ystemObject");

          $version = $fso->GetFileVersion (realpath('some .exe'));
          print $version;

          ?>


          JW



          Comment

          • Peter van Schie

            #6
            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\0 e\0r\0s\0i\0o\0 n\0\0\0\0\0
            The version is right behind that string:

            $strFile = "c:\\my.exe ";
            $fpFile = fopen($strFile, "rb");
            $strFileContent = fread($fpFile, filesize($strFi le));
            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($arrMat ches);
            }

            HTH.
            Peter.
            --

            Comment

            • Iván Sánchez Ortega

              #7
              Re: Get a file's version in PHP

              -----BEGIN PGP SIGNED MESSAGE-----
              Hash: SHA1

              Marius III wrote:
              [color=blue]
              > I want to get the file version of a file in PHP.
              >
              > Do somebody have the code for this?[/color]

              Yeah, it's called "Use a CVS or SVN repository for version tracking" and
              "use external execution commands like shell_exec to query the repository".

              - --
              - ----------------------------------
              Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

              Un ordenador no es un televisor ni un microondas, es una herramienta
              compleja.
              -----BEGIN PGP SIGNATURE-----
              Version: GnuPG v1.4.2 (GNU/Linux)

              iD8DBQFDZK/f3jcQ2mg3Pc8RAm xYAJ4ztjXc/COKd51PaQT5h5Sk GPtcSwCeM8rc
              7GXQnAGTdtLs9no PiG2R4UU=
              =9zCr
              -----END PGP SIGNATURE-----

              Comment

              • Gordon Burditt

                #8
                Re: Get a file's version in PHP

                >> I want to get the file version of a file in PHP.[color=blue][color=green]
                >>
                >> Do somebody have the code for this?
                >>
                >> Thanks alot!
                >>[/color]
                >
                >What do you mean? If you mean the file creation date/last modified date, you
                >can use the filectime/filemtime functions.[/color]

                filectime does not return a "file creation date". Many operating
                systems do not even maintain a file creation date. On the UNIX
                variants that do keep a file creation date (only on UFS2 filesystems),
                that isn't what filectime returns.

                Gordon L. Burditt

                Comment

                Working...