PHP | filectime()函数

PHP中的filectime()函数是一个内置函数,用于返回上次更改指定文件的时间。函数的作用是:成功时将文件最后一次更改的时间作为Unix时间戳返回,失败时返回False。函数的作用是:检查inode更改,即权限、所有者、组或其他元数据的更新,以及常规更改。

null

文件名作为参数传递给filectime()函数。filectime()函数的结果被缓存,一个名为clearstatcache()的函数用于清除缓存。

语法:

filectime($filename)

参数: PHP中的filectime()函数只接受一个参数 $filename 。它指定要检查其上次更改时间的文件。

返回值: 成功时,它将文件的最后更改时间作为Unix时间戳返回,失败时返回False。

错误和例外 :

  1. 不同文件系统的时间分辨率可能不同。
  2. 此功能在某些unix系统上不起作用,这些系统禁用了访问时间更新以提高性能。

例如:

Input : echo filectime("gfg.txt");
Output : 1525159574

Input : echo "Last changed: ".date("F d Y H:i:s.", 
                            filectime("gfg.txt"));
Output : Last changed: May 1 2018 07:26:14.

下面的程序演示了filectime()函数。

方案1 :

<?php
// checking last time a file was changed
echo filectime ( "gfg.txt" );
?>


输出:

1525159574

方案2 :

<?php
// checking last time a file was changed
echo filectime ( "gfg.txt" );
// checking last time a file was changed
// and formatting the output of the date
echo "Last changed: " . date ( "F d Y H:i:s." ,
filectime ( "gfg.txt" ));
?>


输出:

1525159574
Last changed: May 1 2018 07:26:14.

参考: http://php.net/manual/en/function.filectime.php

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享