PHP file creation date, modification date, access time method

Source: Internet
Author: User
This article describes how to obtain the file creation date, modification date, and access time in PHP. sometimes we need to obtain the page generation time to prevent repeated generation. You can refer to common php code for getting the file creation time and modification time.

Filemtime (string filename) returns the time when the file was last modified. If an error occurs, FALSE is returned. Time is returned in Unix timestamp format and can be used for date (). Example: $ a = filemtime ("log.txt"); echo "Modification time :". date ("Y-m-d H: I: s", $ a); filectime (string filename) returns the time when the last inode of the file was modified. If an error occurs, FALSE is returned. Time is returned in Unix timestamp format. Example: $ a = filectime ("log.txt"); echo "creation time :". date ("Y-m-d H: I: s", $ a); fileatime (string filename) returns the time when the object was last accessed. If an error occurs, FALSE is returned. Time is returned in Unix timestamp format. Example: $ a = fileatime ("log.txt"); echo "Modification time:". date ("Y-m-d H: I: s", $ );

Filemtime (string filename)

Returns the time when the file was last modified. If an error occurs, FALSE is returned. Time is returned in Unix timestamp format and can be used for date ().

Filectime (string filename)

Returns the time when the last inode of the file was modified. If an error occurs, FALSE is returned. Time is returned in Unix timestamp format.

Fileatime (string filename)

Returns the time when the object was last accessed. If an error occurs, FALSE is returned. Time is returned in Unix timestamp format.

////////////////////////////

Filectime: Last linux modification time
Filemtime: Last modification time
Fileatime: The Last access time

//////////////////////////////////////// /////////////////////////////////////

Filemtime
(PHP 3, PHP 4)

Filemtime -- get file modification time
Description

Int filemtime (string filename)

Returns the time when the file was last modified. If an error occurs, FALSE is returned. Time is returned in Unix timestamp format and can be used for date ().
Note: the result of this function is cached. For more information, see clearstatcache ().
Note: This function cannot act on remote files. the checked files must be accessed through the file system on the server.
This function returns the time when the data block in the file was last written, that is, the time when the file content was last modified.

Example 1. filemtime () example

 

Filectime
(PHP 3, PHP 4)

Filectime -- get the inode modification time of the file
Description

Int filectime (string filename)

Returns the time when the last inode of the file was modified. If an error occurs, FALSE is returned. Time is returned in Unix timestamp format.
Note: In most Unix file systems, when inode data of a file is changed, the file is considered modified. That is, when the file permission, owner, metadata in all groups or other inode are updated. See filemtime () (this is the function you want to create the "last update time" footer on the web page) and fileatime ().
Note that in some Unix plain text, ctime is the time when the file was created. this is wrong. In most Unix file systems, there is no Unix file creation time.
Note: the result of this function is cached. For more information, see clearstatcache ().
Note: This function cannot act on remote files. the checked files must be accessed through the file system on the server.

Example 1. fileatime () example

 

Fileatime
(PHP 3, PHP 4)

Fileatime -- get the last access time of the file
Description

Int fileatime (string filename)

Returns the time when the object was last accessed. If an error occurs, FALSE is returned. Time is returned in Unix timestamp format.
Note: The atime of a file should be changed whenever the data block in the file is read. Performance is affected when an application regularly accesses a large number of files or directories. Some Unix file systems can disable atime updates during loading to improve the performance of such programs. The USENET newsgroup is a common example. In this file system, this function is useless.
Note: the result of this function is cached. For more information, see clearstatcache ().
Note: This function cannot act on remote files. the checked files must be accessed through the file system on the server.
Example 1. fileatime () example

 

For more information about how to obtain the file creation date, modification date, and access time in PHP, see PHP!

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.