What is the purpose of using filemtime() in PHP and what potential issues can arise when using it?

The purpose of using filemtime() in PHP is to retrieve the last modification time of a file. One potential issue that can arise when using filemtime() is that it may not accurately reflect changes made to a file if the file is being cached by the server or the operating system. To ensure that filemtime() returns the correct modification time, you can use clearstatcache() to clear the file status cache before calling filemtime().

<?php
// Get the last modification time of a file
$file = 'example.txt';
clearstatcache(true, $file);
$lastModified = filemtime($file);
echo "Last modified: " . date("Y-m-d H:i:s", $lastModified);
?>