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

PHP获取远程文件最后更新时间

2008-04-24 23:28 519 查看
<?php
$url = 'http://www.sina.com/index.html';
$headInf = get_headers($url,1);//获取文件头信息
print_r($headInf );//打印文件头信息
echo "/n";
echo $headInf['Last-Modified'];//输出文件最后更新时间
echo "/n";
echo strtotime($headInf['Last-Modified']);//输出最后更新时间UNIX时间戳
?>

运行结果:

Array
(
    [0] => HTTP/1.0 200 OK
    [Date] => Thu, 24 Apr 2008 12:12:31 GMT
    [Server] => Apache/2.0.54 (Unix)
    [Last-Modified] => Wed, 23 Apr 2008 16:49:41 GMT
    [ETag] => "c3fdc1-1bd6-1e7fb340"
    [Accept-Ranges] => bytes
    [Content-Length] => 7126
    [Content-Type] => text/html
    [Age] => 11394
    [X-Cache] => HIT from webfront4.sina.com.cn
    [Connection] => close
)

Wed, 23 Apr 2008 16:49:41 GMT
1208969381

Content-Length项即文件大小,所以从文件头中可以得到文件大小
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php unix etag url server date