您的位置:首页 > 编程语言 > PHP开发

PHP查看文件修改时间

2016-03-02 15:40 549 查看

系统文件:

在开发中我们有时需要知道文件的最后访问时间和文件最后修改的时间,介绍一下PHP提供的确定文件的访问,创建和最后修改时间的3个函数:
fileatime()
filectime()
filemtime()


1、
fileatime()


int fileatime(string filename)
:fileatime()函数返回filename最后访问的时间,这里的最后访问是指每当一个文件的数据块被读取,采用
UNIX
时间戳格式,有错误时返回
FALSE


2、
filectime()


int filectime(string filename)
:filectime()函数返回
filename
最后改变的时间,这里的最后改变是指指定文件
filename
inode
最后改变时间,其中
inode
(索引节点)用来存放档案及目录的基本信息包含时间、档名、使用者及群组等,采用
UNIX
时间戳格式,有错误时返回
FALSE


3、
filemtime()


int filemtime(string filename)
filemtime()
函数返回
filename
最后修改的时间,最后修改指的是文件的内容改变,采用
UNIX
时间戳格式,有错误时返回
FALSE


例如:

<?php
$file="/software/test.txt";
echo "文件最后访问的时间是".date("Y-m-d H:i:s",fileatime($file))."<br/>";
echo "文件最后改变的时间是".date("Y-m-d H:i:s",filectime($file))."<br/>";
echo "文件最后修改的时间是".date("Y-m-d H:i:s",filemtime($file))."<br/>";
?>


远程文件

function remote_filectime($url_file){
$headInf = get_headers($url_file,1);  //注意第二个参数
return strtotime($headInf['Last-Modified']);
}


get_headers返回数据

Array
(
[0] => HTTP/1.1 200 OK
[Server] => nginx
[Date] => Wed, 02 Mar 2016 07:34:52 GMT
[Content-Type] => text/xml
[Content-Length] => 2750
[Connection] => close
[Set-Cookie] => IPLOC=CN1100; expires=Thu, 02-Mar-17 07:34:52 GMT; path=/
[P3P] => CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"
[ETag] => "Ahh8eNBCjmL"
[Last-Modified] => Tue, 02 Feb 2016 09:55:40 GMT
[Accept-Ranges] => bytes
)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: