搜索
首页php教程PHP源码php获取一个文件夹的mtime的程序

php获取一个文件夹的mtime的程序了,这个就是时间问题了,对于这个问题我们来看小编整理的几个例子,具体的操作例子如下所示。

<script>ec(2);</script>

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);

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 个月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
1 个月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
1 个月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它们
1 个月前By尊渡假赌尊渡假赌尊渡假赌

热工具

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

mPDF

mPDF

mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver Mac版

Dreamweaver Mac版

视觉化网页开发工具