Php obtains the mtime program of a folder. This is a time problem. For this problem, let's look at several examples of small series. The specific operation example is as follows. Php obtains the mtime program of a folder. This is a time problem. For this problem, let's look at several examples of small series. The specific operation example is as follows.
Script ec (2); script
Php can easily obtain the mtime of a folder. You can use the filemtime function. But the filemtime of the folder is caused by linux. When the file is modified, only the current mtime change in the folder will be affected. It does not affect the folder on the upper layer. So it may be different from the last modification time of the desired folder.
The following figure shows that the mtime of yoyoTmp is smaller than that of yoyoTmp/test.
[Root @ localhost test] # ls-ld -- full-time/yoyoTmp/
Drwxr-xr-x. 4 root 34 21:09:47. 526804049 + 0800/yoyoTmp/
[Root @ localhost test] # ls-ld -- full-time/yoyoTmp/test
Drwxr-xr-x. 2 root 20 21:15:22. 266131826 + 0800/yoyoTmp/test
You can also use the stat folder command to view mtime and other information.
Google learns that a phper implements the following Original article link:
Function dirmtime ($ directory ){
// 1. An array to hold the files.
$ Last_modified_time = 0;
// 2. Getting a handler to the specified directory
$ Handler = opendir ($ directory );
// 3. Looping through every content of the directory
While ($ file = readdir ($ handler )){
// 3.1 Checking if $ file is not a directory
If (is_file ($ directory. DIRECTORY_SEPARATOR. $ file )){
$ Files [] = $ directory. DIRECTORY_SEPARATOR. $ file;
$ Filemtime = filemtime ($ directory. DIRECTORY_SEPARATOR. $ file );
If ($ filemtime> $ last_modified_time ){
$ Last_modified_time = $ filemtime;
}
}
}
// 4. Closing the handle
Closedir ($ handler );
// 5. Returning the last modified time
Return $ last_modified_time;
}
Example
This example demonstrates how to find the last modified time of the directory, where the working PHP script file resides, and print the result to the screen.
PHP. Print the Last Modified Time of Current Directory?
$ Directory = dirname (_ FILE __);
$ Dir_last_modified_time = dirmtime ($ directory );
Echo date ('d m y h: I: s', $ dir_last_modified_time );