PHP中获取文件创建日期、修改日期、访问时间的方法

2019-05-02 16:40:21刘景俊

注意某些 Unix 说明文本中把 ctime 说成是该文件建立的时间,这是错的。在大多数 Unix 文件系统中没有 Unix 文件的建立时间。
注: 本函数的结果会被缓存。详细信息参见 clearstatcache()。
注: 本函数不能作用于远程文件,被检查的文件必须通过服务器的文件系统访问。

例子 1. fileatime() 例子

<?php

// 输出类似:somefile.txt was last changed: December 29 2002 22:16:23.

$filename = 'somefile.txt';
if (file_exists($filename)) {
 echo "$filename was last changed: " . date ("F d Y H:i:s.", filectime($filename));
}
?>

fileatime
(PHP 3, PHP 4 )

fileatime -- 取得文件的上次访问时间
说明

int fileatime ( string filename)

返回文件上次被访问的时间,如果出错则返回 FALSE。时间以 Unix 时间戳的方式返回。
注意:一个文件的 atime 应该在不论何时读取了此文件中的数据块时被更改。当一个应用程序定期访问大量文件或目录时很影响性能。有些 Unix 文件系统可以在加载时关闭 atime 的更新以提高这类程序的性能。USENET 新闻组假脱机是一个常见的例子。在这种文件系统下本函数没有用处。
注: 本函数的结果会被缓存。详细信息参见 clearstatcache()。
注: 本函数不能作用于远程文件,被检查的文件必须通过服务器的文件系统访问。
例子 1. fileatime() 例子

<?php
// 输出类似:somefile.txt was last accessed: December 29 2002 22:16:23.
$filename = 'somefile.txt';
if (file_exists($filename)) {
 echo "$filename was last accessed: " . date ("F d Y H:i:s.", fileatime($filename));
}
?>

相关文章 大家在看