How can predefined constants be utilized in PHP to access file modification information?
Predefined constants in PHP, such as `filemtime()` and `filectime()`, can be utilized to access file modification information. These constants allow you to retrieve the timestamp of when a file was last modified or when its inode was last changed. By using these predefined constants, you can easily retrieve and display file modification information in your PHP code.
$filename = 'example.txt';
// Get the timestamp when the file was last modified
$lastModified = filemtime($filename);
// Get the timestamp when the file's inode was last changed
$lastInodeChange = filectime($filename);
echo "File last modified: " . date('Y-m-d H:i:s', $lastModified) . "<br>";
echo "File last inode change: " . date('Y-m-d H:i:s', $lastInodeChange);
Related Questions
- What are best practices for preserving the original file name and extension during file uploads in PHP?
- What best practices should be followed when storing and calculating time intervals in PHP, particularly when dealing with milliseconds?
- How can the "Notice: Use of undefined constant" error be resolved in PHP when using the date function?