0

In the same directory on the server as the html page I have a log that comes from an application. I want to check this file exists and the size or modified date of this file.

This needs to be in a simple JavaScript function that looks for the file and confirms it exists and the size or time modified of the file.

This is so I can update or reload my html page if there is new data. The data itself is being transformed via xslt. Is there something like this I can do:

function checkForLog() {
  let logFile = new File([""],"./report.log");
  let size = logFile.size;

  if (size > previousSize){
    location.reload(true);
  }    
}

I tried this but it returns 0 even though the file report.log is 56kb so it seems this logFile is a new file instance and not actually a reference to my file in the directory.

TobyJEP
  • 1
  • 1
  • 2
    From the browser, your JavaScript code will have to issue an HTTP request to an API on your server to check for the file. The browser JavaScript code runs on the *client*, and so it cannot directly look at the server file system. – Pointy Dec 22 '21 at 15:04

0 Answers0