How can PHP be used to determine the last modification date of a file?
To determine the last modification date of a file using PHP, you can use the `filemtime()` function. This function returns the timestamp when the file was last modified. You can then use the `date()` function to format the timestamp into a human-readable date format.
$filename = 'example.txt';
if (file_exists($filename)) {
$lastModified = filemtime($filename);
echo "Last modified date: " . date("Y-m-d H:i:s", $lastModified);
} else {
echo "File not found!";
}
Related Questions
- What are best practices for troubleshooting and debugging issues related to the $_POST variable in PHP scripts, especially when var_dump() returns unexpected results?
- How can dynamic routing be implemented in PHP to avoid unnecessary redirection loops?
- What are the challenges and considerations when migrating from PHP4 to PHP5 on a server without gcc installed?