find the last accessed date of a file in php

You can use the stat() function in PHP to get the last accessed time of a file. Here's an example:

main.php
$file_path = '/path/to/your/file.txt';
$file_stat = stat($file_path);

$last_accessed = $file_stat['atime']; // Last accessed time in UNIX timestamp format

echo "Last accessed on " . date("Y-m-d H:i:s", $last_accessed);
221 chars
7 lines

This will display the last accessed time of the file in a human-readable format. You can also use the fileatime() function, which is a shortcut for calling stat() and returning just the last accessed time:

main.php
$file_path = '/path/to/your/file.txt';
$last_accessed = fileatime($file_path);

echo "Last accessed on " . date("Y-m-d H:i:s", $last_accessed);
144 chars
5 lines

Both of these methods will give you the last accessed time of a file in PHP. If you need to get the last modification time, you can use filemtime() or retrieve the 'mtime' value from the stat() function.

gistlibby LogSnag