What is the function used to get 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 the last modification time of the specified file. You can then use this timestamp with the `date()` function to format it into a human-readable date and time.
$filename = 'example.txt';
$lastModifiedTime = filemtime($filename);
$lastModifiedTimeString = date("Y-m-d H:i:s", $lastModifiedTime);
echo "Last modified time of $filename: $lastModifiedTimeString";
Keywords
Related Questions
- Is it necessary to initialize an array in PHP before adding elements to it, and what impact does this have on error handling and notices?
- What potential issues can arise from relying on the User Agent for login and session management in PHP applications?
- What are the potential pitfalls of using the DateTime class in PHP for beginners?