您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php获取一个文件夹的mtime的程序

2024/3/17 7:33:05发布23次查看
php获取一个文件夹的mtime的程序了,这个就是时间问题了,对于这个问题我们来看小编整理的几个例子,具体的操作例子如下所示。
php很容易获取到一个文件夹的mtime,可以使用filemtime函数。但文件夹的filemtime由于linux的原因。文件修改时,只会影响他当前的文件夹mtime变化。并不会继续影响文件夹上层的文件夹。所以可能跟真正想得到的文件夹的最后修改时间不同。
看linux机器上的效果如下, 可以看到yoyotmp的mtime小于yoyotmp/test的mtime。
[root@localhost test]# ls -ld --full-time /yoyotmp/
drwxr-xr-x. 4 root root 34 2015-12-01 21:09:47.526804049 +0800 /yoyotmp/
[root@localhost test]# ls -ld --full-time /yoyotmp/test
drwxr-xr-x. 2 root root 20 2015-12-01 21:15:22.266131826 +0800 /yoyotmp/test
也可使用stat 文件夹命令查看mtime之类信息
google得知一个phper实现了如下 原文链接:
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);
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product