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