A brief description of how PHP obtains file size and creation time

Source: Internet
Author: User
This article mainly introduces PHP to get file size and file creation time method, involving PHP filesize and fileatime function of the use of skills, with a certain reference value, the need for friends can refer to the next

This example describes how PHP obtains file size and file creation time. The specific analysis is as follows:

PHP can display various properties of a file, including the last access time of the file, the last modification time, the file size, and so on.


Filemtime (string filename)

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

Filectime (string filename)

Returns the time the file last Inode was modified and returns FALSE if an error occurs. Time is returned as a Unix timestamp.

Fileatime (string filename)

Returns the time that the file was last accessed, or FALSE if an error occurs. Time is returned as a Unix timestamp.

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

Filectime:linux Last Modified Time
Filemtime: Last Modification 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 and FALSE on error. Time is returned as a Unix timestamp and can be used with date ().
Note: The result of this function is cached. For more information, see Clearstatcache ().
Note: This function does not work on remote files, and the files being inspected must be accessed through the server's file system.
This function returns the last time the data block in the file was written, that is, the time when the contents of the file were last modified.

Example 1. Filemtime () example

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

Filectime
(PHP 3, PHP 4)

Filectime--Get the Inode modification time of the file
Description

int Filectime (string filename)

Returns the time the file last Inode was modified and returns FALSE if an error occurs. Time is returned as 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 permissions of the file, the owner, all the groups, or other metadata in the Inode are updated. See Filemtime () (This is the function you want to use to create a "last updated" footnote in a Web page) and Fileatime ().
It is wrong to note that CTime is said to be the time that the file was established in some Unix explanatory text. There is no setup time for UNIX files in most Unix file systems.
Note: The result of this function is cached. For more information, see Clearstatcache ().
Note: This function does not work on remote files, and the files being inspected must be accessed through the server's file system.

Example 1. Fileatime () example

<?php//output similar to: Somefile.txt is last Changed:december 2002 22:16:23. $filename = ' somefile.txt '; if (file_exists ($file Name) {  echo "$filename is last changed:". Date ("F D Y h:i:s.", Filectime ($filename));}? >

Fileatime
(PHP 3, PHP 4)

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

int Fileatime (string filename)

Returns the time that the file was last accessed, or FALSE if an error occurs. Time is returned as a Unix timestamp.
Note: The atime of a file should be changed whenever a block of data in this file is read. Performance is affected when an application regularly accesses a large number of files or directories. 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 under this file system.
Note: The result of this function is cached. For more information, see Clearstatcache ().
Note: This function does not work on remote files, and the files being inspected must be accessed through the server's file system.
Example 1. Fileatime () example

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

Summary : The above is the entire content of this article, I hope to be able to help you learn.

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.