Home  >  Article  >  Backend Development  >  How to get the last modification time of a file in PHP?

How to get the last modification time of a file in PHP?

Guanhui
GuanhuiOriginal
2020-07-23 11:56:022983browse

How to get the last modification time of a file in PHP?

#How to get the last modification time of a file in PHP?

In PHP, you can easily obtain the last modification time of a file through the system's own function "filemtime()". Its function is to return the time when the file was last modified. An error occurs. Returns FALSE.

<?php
$a=filemtime("log.txt");
echo "修改时间:".date("Y-m-d H:i:s",$a)."
?>

Knowledge Extension

filemtime ( string filename )

Returns the time when the file was last modified, and returns FALSE on error. The time is returned as a Unix timestamp, usable with date().

For example:

$a=filemtime("log.txt");
echo "修改时间:".date("Y-m-d H:i:s",$a)."

---------------------------------- -----------------------------------------------

filectime ( string filename )

Returns the time when the file's last inode was modified, or FALSE if an error occurs. The time is returned as a Unix timestamp.

For example:

$a=filectime("log.txt");
          echo "创建时间:".date("Y-m-d H:i:s",$a)."

---------------------------------- -----------------------------------------------

fileatime ( string filename )

Returns the time when the file was last accessed, or FALSE if an error occurred. The time is returned as a Unix timestamp.

For example:

$a=fileatime("log.txt");
echo "修改时间:".date("Y-m-d H:i:s",$a)."

Recommended tutorial: "PHP"

The above is the detailed content of How to get the last modification time of a file in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn