加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP最后修改远程文件的时间

发布时间:2020-12-13 17:51:49 所属栏目:PHP教程 来源:网络整理
导读:我想获得远程文件的最后修改时间.我正在使用我在stackoverflow上找到的代码 $curl = curl_init(); curl_setopt($curl,CURLOPT_URL,$url); //don't fetch the actual page,you only want headers curl_setopt($curl,CURLOPT_NOBODY,true); curl_setopt($curl,
我想获得远程文件的最后修改时间.我正在使用我在stackoverflow上找到的代码
$curl = curl_init();

    curl_setopt($curl,CURLOPT_URL,$url);
    //don't fetch the actual page,you only want headers
    curl_setopt($curl,CURLOPT_NOBODY,true);
    curl_setopt($curl,CURLOPT_HEADER,true);
    //stop it from outputting stuff to stdout
    curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);

    // attempt to retrieve the modification date
    curl_setopt($curl,CURLOPT_FILETIME,true);

    $result = curl_exec($curl);
    echo $result;
    $info = curl_getinfo($curl);
    print_r($info);
    if ($info['filetime'] != -1) { //otherwise unknown
        echo date("Y-m-d H:i:s",$info['filetime']); //etc
    }

这段代码的问题我一直在获得filetime = -1.但是当我删除

curl_setopt($curl,true);

然后我得到正确的修改时间.

是否有可能获得最后的修改时间,但有

curl_setopt($curl,true);

包含在脚本中.
我只需要页面的标题,而不是正文.

提前致谢

鉴于我们在Q / A讨论中添加的信息,确实听起来你只是没有得到回应.可能是服务器配置了某种故意或无意中由于某种原因阻止HEAD请求,或者可能涉及困难的代理.

当我调试PHP cURL的东西时,我经常发现使用* nix框(我的mac或ssh到服务器)并从命令行运行请求很有用,所以我可以看到结果而不用担心是否PHP正在做正确的事情,直到我让cURL部分工作.例如:

$curl --head stackoverflow.com

HTTP/1.1 200 OK
Cache-Control: public,max-age=49
Content-Length: 190214
Content-Type: text/html; charset=utf-8
Expires: Mon,10 Oct 2011 07:22:07 GMT
Last-Modified: Mon,10 Oct 2011 07:21:07 GMT
Vary: *
Date: Mon,10 Oct 2011 07:21:17 GMT

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读