


How to get the time attribute (information) of the file in php file operation
In the previous article, we introduced the method of obtaining file attributes and checking whether the file is readable, writable, and executable. If you are interested, you can click the link to insert → "php file operation: check whether the file is executable. Read/Write/Execute》. Next, this article will continue to talk about file attributes and look at how to obtain file time attributes.
The file contains three time attributes (information), namely: Creation time, Modification time and Last access time.
For example, the following text file named "test.txt", its creation time, modification time and last access time are as follows:
So how do we get the three file attributes? Don’t panic, PHP provides three functions to get them:
filectime($filename)
: Returns the creation time of the filefilemtime($filename)
: Returns the last modification time of the filefileatime($filename)
: Returns The last access time of the file
Let’s take a look at the following code example:
<?php header("Content-type:text/html;charset=utf-8"); $file = "test.txt"; echo "文件创建时间为:".filectime($file); echo "<br>文件修改时间为:".filemtime($file); echo "<br>文件上次访问的时间为:".fileatime($file); ?>
Output result:
By outputting the results, you will find that the three functions filectime(), filemtime() and fileatime() return time in the form of Unix timestamp, which is not conducive to reading, we can use ## The #date() function processes the obtained time and formats it into the specified "Y-m-d H:i:s" format.
<?php header("Content-type:text/html;charset=utf-8"); $file = "test.txt"; echo "文件创建时间为:".date('Y-m-d H:i:s',filectime($file)); echo "<br>文件修改时间为:".date('Y-m-d H:i:s',filemtime($file)); echo "<br>文件上次访问的时间为:".date('Y-m-d H:i:s',fileatime($file)); ?>Output result:
Entering the World of PHP from 0" ~ Come and learn!
The above is the detailed content of How to get the time attribute (information) of the file in php file operation. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver CS6
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
