Home >Backend Development >PHP Problem >How to get the file modification time in php?
Obtaining method: 1. Use the filemtime() function to return the last time the file content was modified. The syntax format is "filemtime(file);"; 2. Use the filectime() function to return the last time the file content was modified. The time when file permissions, owners, etc. were modified, the syntax format is "filectime(file);".
Recommendation: "PHP Video Tutorial"
#php method to get file modification time
Method 1: Use the php filemtime() function
The filemtime() function returns the last modification time of the file content.
If successful, this function will return the last modification time of the file contents in the form of a Unix timestamp, which can be used with date(). On failure, returns FALSE.
Syntax
filemtime(filename)
filename: required. Specifies the documents to be checked.
#Note: The result of this function will be cached. Please use clearstatcache() to clear the cache.
Example:
<?php $a=filemtime("log.txt"); echo "修改时间:".date("Y-m-d H:i:s",$a); ?>
Method 2: Use php filectime() function
filectime() function returns the specified file 's last modification time.
This function will check the daily modification of the file and the inode modification. Inode modification refers to: modification of permissions, modification of owner, modification of user group or modification of other metadata.
If successful, this function will return the last modification time of the file as a Unix timestamp. On failure, returns FALSE.
Syntax
filectime(filename)
filename Required. Specifies the documents to be checked.
#Note: The result of this function will be cached. Please use clearstatcache() to clear the cache.
Tip: Please use the filemtime() function to return the time when the file content was last modified.
Example:
<?php echo "上一次更改的时间: ".date("F d Y H:i:s.",filectime("test.txt")); ?>
The above code will output:
上一次更改的时间: January 30 2020 09:26:32.
Related recommendations:php training
The above is the detailed content of How to get the file modification time in php?. For more information, please follow other related articles on the PHP Chinese website!