How to get file creation date, modification date, access time in PHP _php Foundation

Source: Internet
Author: User

PHP gets file creation time, modified time common code

Filemtime (string filename)
returns the time when the file was last modified, FALSE when an error occurred. Time is returned as a Unix timestamp and can be used for date ().
For example: $a =filemtime ("Log.txt");
      echo "Modify Time:". Date ("Y-m-d h:i:s", $a);
Filectime (string filename)
returns the time when the last inode was modified, or FALSE if an error occurs. Time is returned in the form of a Unix timestamp.
For example: $a =filectime ("Log.txt");
      echo "Creation time:". 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 occurs. Time is returned in the form of a Unix timestamp.
For example: $a =fileatime ("Log.txt");
     echo "Modify Time:". Date ("Y-m-d h:i:s", $a);

Filemtime (string filename)

Returns the time when the file was last modified, FALSE when an error occurred. Time is returned as a Unix timestamp and can be used for date ().

Filectime (string filename)

Returns the time when the last inode was modified, or FALSE if an error occurs. Time is returned in the form of a Unix timestamp.

Fileatime (string filename)

Returns the time when the file was last accessed, or FALSE if an error occurs. Time is returned in the form of a Unix timestamp.

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

Filectime:linux Last Modification time
Filemtime: Last Modified time
Fileatime: Time of last visit

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

Filemtime
(PHP 3, PHP 4)

Filemtime--Get File modification time
Description

int Filemtime (string filename)

Returns the time when the file was last modified, FALSE when an error occurred. Time is returned as a Unix timestamp and can be used for date ().
Note: The result of this function will be cached. For more information, see Clearstatcache ().
Note: This function does not work on remote files, and the files that are checked must be accessed through the server's file system.
This function returns the time when the block of data in the file was last written, that is, when the contents of the file were last modified.

Example 1. Filemtime () example

<?php
//outputs e.g Somefile.txt was last Modified:december 2002.
$filename = ' somefile.txt ';
if (file_exists ($filename)) {
 echo "$filename is Last modified:". Date ("F D Y h:i:s.", Filemtime ($filename));
>

Filectime
(PHP 3, PHP 4)

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

int Filectime (string filename)

Returns the time when the last inode was modified, or FALSE if an error occurs. Time is returned in the form of a Unix timestamp.
Note: In most Unix file systems, when the Inode data for a file is changed, the file is considered modified. That is, when the file's permissions, owner, all groups or other inode's metadata is updated. See Filemtime () (This is the function you want to use to create the "last updated" footnote in a Web page) and Fileatime ().
It is wrong to note that CTime is described in some Unix instruction text as the time the file was established. There is no time to establish UNIX files in most Unix file systems.
Note: The result of this function will be cached. For more information, see Clearstatcache ().
Note: This function does not work on remote files, and the files that are checked must be accessed through the server's file system.

Example 1. Fileatime () example

<?php

//output is similar: Somefile.txt was last Changed:december 2002 22:16:23.

$filename = ' somefile.txt ';
if (file_exists ($filename)) {
 echo "$filename is last changed:". Date ("F D Y h:i:s.", Filectime ($filename));
>

Fileatime
(PHP 3, PHP 4)

Fileatime-Gets the file's last access time
Description

int Fileatime (string filename)

Returns the time when the file was last accessed, or FALSE if an error occurs. Time is returned in the form of a Unix timestamp.
Note: The atime of a file should be changed whenever a block of data in this file is read. When an application accesses a large number of files or directories on a regular basis, performance is affected. Some Unix file systems can turn off atime updates at load time to improve the performance of such programs. USENET newsgroup spooling is a common example. This function is not useful in this file system.
Note: The result of this function will be cached. For more information, see Clearstatcache ().
Note: This function does not work on remote files, and the files that are checked must be accessed through the server's file system.
Example 1. Fileatime () example

<?php
//output is similar: Somefile.txt was last Accessed:december 2002 22:16:23.
$filename = ' somefile.txt ';
if (file_exists ($filename)) {
 echo "$filename is last accessed:". Date ("F D Y h:i:s.", Fileatime ($filename));
>

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.