PHP中的filemtime()函数是一个内置函数,用于在修改指定文件的内容时返回该文件的最后一次时间。函数的作用是:成功时将上次更改文件的时间作为Unix时间戳返回,失败时返回False。
null
文件名作为参数传递给filemtime()函数。filemtime()函数的结果被缓存,一个名为clearstatcache()的函数用于清除缓存。
语法:
filemtime($filename)
参数: PHP中的filemtime()函数只接受一个参数 $filename 。它指定要检查的文件。
返回值: 成功时,它返回文件内容被修改为Unix时间戳的最后时间,失败时返回False。
错误和例外 :
- 不同文件系统的时间分辨率可能不同。
- 此功能在某些unix系统上不起作用,这些系统禁用了访问时间更新以提高性能。
例如:
Input : echo filemtime("gfg.txt"); Output : 1525159574 Input : echo "Last modified: ".date("F d Y H:i:s.", filemtime("gfg.txt")); Output : Last modified: May 1 2018 07:26:14.
下面的程序演示了filemtime()函数。
方案1 :
<?php // checking last time the contents // of a file were changed echo filemtime ( "gfg.txt" ); ?> |
输出:
1525159574
方案2 :
<?php // checking last time the contents // of a file were changed echo filemtime ( "gfg.txt" ); // checking last time the contents of // a file were changed and formatting // the output of the date echo "Last modified: " . date ( "F d Y H:i:s." , filemtime ( "gfg.txt" )); ?> |
输出:
1525159574 Last modified: May 1 2018 07:26:14.
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END