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 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址