So I'm really new on this kind of world, never actually had a HTTP server before. I'm just making some kind of presentation website for a game server I'm hosting, and I have this zip file full of mods for it, accessible from the website so one can just click and download.
The point is, between mod updates and additions, this zip file gets modified plenty of times. Is there a way, either with HTML of JavaScript, to show the last time the file was modified?
CodePudding user response:
When just using JavaScript, this is (to my knowledge) impossible without downloading the file first and then reading its' properties.
If, however, your HTML file is being modified at the same time the zip file is modified, you can do something like this:
document.getElementById("text").innerText = document.lastModified;
<span id="text"></span>
On most simple websites, the document.lastModified
property will show you when the HTML file was last modified. You can test it out on different websites by going to them, right-clicking anywhere and selecting "Inspect element". Then, in the console, you can type document.lastModified;
and it will show you the date it was last modified.
CodePudding user response:
After investigating a bit further, turns out that, instead of JS, PHP had the solution to my problem. Posting below the code used.
$filename = 'mods.zip';
if (file_exists($filename)) {
echo "Last updated: " . date ("d/m/Y H:i:s.", filemtime($filename));
}