Home Backend Development PHP Tutorial Check file modification time with PHP

Check file modification time with PHP

Jul 29, 2016 am 09:01 AM
filectime filemtime gt

System files:

In development, we sometimes need to know the last access time and last modification time of a file. Let’s introduce the three functions provided by PHP to determine the access, creation and last modification time of a file: fileatime() , filectime() and filemtime().
1. fileatime()
int fileatime(string filename): The fileatime() function returns the last access time of filename. The last access here refers to whenever a data block of a file is read, using UNIXtime Stamp format, returns FALSE if there is an error.
2. filectime()
int filectime(string filename): The filectime() function returns the last change time of filename. The last change here refers to the last change time of inode of the specified file filename, where inode (index node) is used to store basic information of files and directories including time, file name, user and group, etc. It adopts UNIX timestamp format and returns FALSE when there is an error.
3. filemtime()
int filemtime(string filename): The filemtime() function returns the last modification time of filename. The last modification refers to the change of the content of the file, using the UNIX timestamp format. Returns FALSE if there is an error.
For example:

<code><span><span><?php</span><span>$file</span>=<span>"/software/test.txt"</span>; 
<span>echo</span><span>"文件最后访问的时间是"</span>.date(<span>"Y-m-d H:i:s"</span>,fileatime(<span>$file</span>)).<span>"<br/>"</span>; 
<span>echo</span><span>"文件最后改变的时间是"</span>.date(<span>"Y-m-d H:i:s"</span>,filectime(<span>$file</span>)).<span>"<br/>"</span>; 
<span>echo</span><span>"文件最后修改的时间是"</span>.date(<span>"Y-m-d H:i:s"</span>,filemtime(<span>$file</span>)).<span>"<br/>"</span>; 
<span>?></span></span></code>
Copy after login

Remote files

<code><span><span>function</span><span>remote_filectime</span><span>(<span>$url_file</span>)</span>{</span><span>$headInf</span> = get_headers(<span>$url_file</span>,<span>1</span>);  <span>//注意第二个参数 </span><span>return</span> strtotime(<span>$headInf</span>[<span>'Last-Modified'</span>]);   
} </code>
Copy after login

get_headers return data

<code><span>Array</span>
(
    [<span>0</span>] => HTTP/<span>1.1</span><span>200</span> OK
    [Server] => nginx
    [Date] => Wed, <span>02</span> Mar <span>2016</span><span>07</span>:<span>34</span>:<span>52</span> GMT
    [Content-Type] => text/xml
    [Content-Length] => <span>2750</span>
    [Connection] => close
    [Set-Cookie] => IPLOC=CN1100; expires=Thu, <span>02</span>-Mar-<span>17</span><span>07</span>:<span>34</span>:<span>52</span> GMT; path=/
    [P3P] => CP=<span>"CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"</span>
    [ETag] => <span>"Ahh8eNBCjmL"</span>
    [Last-Modified] => Tue, <span>02</span> Feb <span>2016</span><span>09</span>:<span>55</span>:<span>40</span> GMT
    [Accept-Ranges] => bytes
)</code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces PHP to check the file modification time, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

PHP function introduction—filemtime(): Get the last modification time of a file PHP function introduction—filemtime(): Get the last modification time of a file Jul 24, 2023 pm 05:41 PM

PHP function introduction—filemtime(): Get the last modification time of a file Overview: In PHP, filemtime() is a very commonly used function, used to get the last modification time of a file. Through this function, we can get the last modification timestamp of the file to facilitate the operation and processing of the file. This article will introduce how to use the filemtime() function and provide code examples to help readers better understand and use this function. Function syntax: intfilemtime

How to Fix Can't Connect to App Store Error on iPhone How to Fix Can't Connect to App Store Error on iPhone Jul 29, 2023 am 08:22 AM

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

PHP function introduction—filectime(): Get the creation time of a file PHP function introduction—filectime(): Get the creation time of a file Jul 24, 2023 pm 01:37 PM

Introduction to PHP functions—filectime(): Get the creation time of a file. PHP is a scripting language used to develop web applications. It has a rich function library and provides developers with a lot of convenience. Among them, the filectime() function is a very useful function, which can help us get the creation time of the file. The filectime() function returns the timestamp of the creation time of a file. The timestamp is an elapsed time since January 1, 1970 00:00:00GMT

Use the PHP function 'filemtime' to return the modification time of a file Use the PHP function 'filemtime' to return the modification time of a file Jul 24, 2023 am 10:01 AM

The PHP function "filemtime" can be used to get the last modification time of a file. Its use is very simple, just pass in the file path as a parameter, and the function will return a timestamp indicating the last modification time of the file. Next, I will introduce how to use this function and some code examples. In PHP, we can use the "filemtime" function in the following way: $file_path='path/to/file.txt';//File path

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

PHP function introduction: is_file() function PHP function introduction: is_file() function Nov 04, 2023 am 09:11 AM

PHP function introduction: is_file() function In PHP programming, the is_file() function is a very useful function. It is used to determine whether a path or file exists and is an ordinary file. In this article, we will introduce how to use the is_file() function and provide some specific code examples. First, let's take a look at the syntax of the is_file() function: boolis_file(string$filename)is_

See all articles