What are some alternative functions or methods in PHP that can be used to check the modification time of files before deleting them?

When deleting files in PHP, it's important to check the modification time of the file to ensure that you are not accidentally deleting a file that has been recently modified. One way to do this is by using the filemtime() function to get the last modification time of the file before deciding to delete it.

$filename = 'example.txt';

// Get the last modification time of the file
$lastModifiedTime = filemtime($filename);

// Check if the file was modified within the last 24 hours
if (($lastModifiedTime + 86400) > time()) {
    // File was modified within the last 24 hours, do not delete
    echo "File was modified within the last 24 hours, cannot delete.";
} else {
    // File was not modified within the last 24 hours, safe to delete
    unlink($filename);
    echo "File deleted successfully.";
}