dongnu4254 2016-10-27 13:15 采纳率: 100%
浏览 71
已采纳

ftp_mdtm函数根据日期获取最新修改的图像

I am downloading remote images from one server to another and that part I did good. Now I need to download only the newest modified images. Before I even get to that, I am trying to show modification time for all images using ftp_mdtm function. But I keep getting

was last modified on : January 01 1970 01:00:00

I googled and looked for the answer here, but everything I tried didn't help me. The entire code is here:

    <?php
    $ftp_server = "xxx.xxx.xxx.xxx";
    $ftp_user = "xxx";
    $ftp_pass = "xxx";
    $DIR="/xxx/";

    $conn = ftp_connect($ftp_server);
 if(!$conn) {
 exit("Can not connect to: $ftp_server
");
 }

 if(!ftp_login($conn,$ftp_user,$ftp_pass)) {
 ftp_quit($conn);
 exit("Can not log on to
");
 }

 ftp_chdir($conn,$DIR);

 $files = ftp_nlist($conn,'.');
//var_dump($files);
 for($i=0;$i<count($files);$i++) {

 if(!ftp_get($conn,$files[$i],$files[$i],FTP_BINARY )) {
 echo "Can not download {$files[$i]}
";
 }
 else {echo "Success";
 $buff = ftp_mdtm($conn_id, $file);

if ($buff != -1) {

    echo "$file was last modified on : " . date("F d Y H:i:s.", $buff);
} else {
    echo "Couldn't get mdtime";
}
 }

 }


 ftp_quit($conn);
 ?>
  • 写回答

1条回答 默认 最新

  • doushi9376 2016-10-27 13:40
    关注

    UPDATE: Thanx to great question by @arkascha, I realized I made a mistake in my code. The $buff variable was defined in a wrong way. The correct way is as follows:

         $buff = ftp_mdtm($conn_id);
    
    if ($buff != -1) {
    
        echo "$file was last modified on : " . date("F d Y H:i:s.");
           } else {
        echo "Couldn't get mdtime";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记