PHP Gets a mtime program for a folder

Source: Internet
Author: User
Tags echo date php script

PHP is easy to get to the mtime of a folder, you can use the Filemtime function. But the Filemtime for the folder is due to Linux. When a file is modified, it only affects his current folder Mtime changes. Does not continue to affect folders at the top of the folder. So it might be different from the last modification of the folder you really want.

Look at the results on the Linux machine as follows, you can see the yoyotmp mtime is less than yoyotmp/test mtime.

[Root@localhost test]# ls-ld--full-time/yoyotmp/
Drwxr-xr-x. 4 Root 2015-12-01 21:09:47.526804049 +0800/yoyotmp/
[Root@localhost test]# ls-ld--full-time/yoyotmp/test
Drwxr-xr-x. 2 root 2015-12-01 21:15:22.266131826 +0800/yoyotmp/test
You can also use the Stat Folder command to view information such as Mtime

Google learned that a phper implemented the following text 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 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 is example demonstrates the last modified of the directory, where the working PHP script file resides, and print 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);

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.