Search code examples
javascripthtmlfileversioninfogetfileversion

Get Version info for download file in HTML


Our website includes a link where customers can download the latest update.exe files. We'd like to have the web page automatically display the file version info of each patch file. The files are digitally signed native windows executables.

Is there a way to get and display the version info from the files using HTML5 or javascript without having the user have to click a button? In essence, we want the file versions to update when the page loads or is refreshed. Here's what we have now. I'd like to add "Version 1.2.3.4" after where it says "Product" on each line.

<ul class="links">
    <li>Latest Patches:</li>
    <li><a href="updateFoo.exe">Update for Foo Product </a></li>
    <li><a href="updateBar.exe">Update for Bar Product </a></li>
    <li><a href="updateYou.exe">Update for You Product </a></li>
</ul>

Solution

  • It would be better to find the file version at the server side. If you do it at the client side, JavaScript would have to download at-least the first few chunks of each file.

    If you want to keep the HTML file intact, you can make Ajax requests to server side where a server side script such as php file will return file version for each of these files. An example for such a php function can be found here: Extract internal EXE info

    Following example shows how you can fetch file versions via Ajax from server side and write next to each download link.

    <script src="https://raw.githubusercontent.com/vishva8kumara/arc-reactor/master/arc.js"></script>
    
    <ul class="links">
        <li>Latest Patches:</li>
        <li><a href="updateFoo.exe" class="fetchVersion">Update for Foo Product </a></li>
        <li><a href="updateBar.exe" class="fetchVersion">Update for Bar Product </a></li>
        <li><a href="updateYou.exe" class="fetchVersion">Update for You Product </a></li>
    </ul>
    
    <script>
        var links = q('.fetchVersion');
        for (var i = 0; i < links.length; i++)
            new ajax('getVersion.php?file='links[i].getAttribute('href'),
                {
                    callback: function(data, ref){
                        ref.appendChild(elem('span', data.responseText));
                    }
                }, links[i])
    </script>
    

    And on the server, create a file getVersion.php that accepts $_GET['file'], call the getFileVersionInfo function and writes the file info to the output buffer.