What is the correct function to use for getting the last modification time of a file in PHP?
To get the last modification time of a file in PHP, you can use the `filemtime()` function. This function returns the Unix timestamp of when the file was last modified. You can then use the `date()` function to format this timestamp into a human-readable date and time.
$filename = 'example.txt';
$lastModifiedTime = filemtime($filename);
$lastModifiedDateTime = date("Y-m-d H:i:s", $lastModifiedTime);
echo "Last modified time of $filename: $lastModifiedDateTime";
Keywords
Related Questions
- What is the common syntax error in PHP code that results in a "Parse error"?
- What are the differences in handling navigation in MediaWiki compared to other CMS platforms in PHP?
- What are the best practices for handling network connections and data retrieval in PHP scripts like fetching values from a remote server?