find the last accessed date of a json file in php

You can use the filemtime() function in PHP to find the last modified time of a file. If the file doesn't exist, filemtime() returns false. But you can also use the file_exists() function to check if the file exists before calling filemtime().

Here's an example code snippet to find the last accessed time of a JSON file:

main.php
$filename = 'path/to/file.json';

if (file_exists($filename)) {
    $lastAccessedTime = filemtime($filename);
    echo("The last accessed time of $filename is: " . date("F d Y H:i:s.", $lastAccessedTime));
} else {
    echo("$filename does not exist.");
}
256 chars
9 lines

In the example above, we first check if the file exists using file_exists(). If it does, we call filemtime() to get the last accessed time of the file. We then format the time using the date() function and print it out. If the file doesn't exist, we print out an error message.

gistlibby LogSnag