PHP ftp_mdtm()函数用法详细介绍

2021年4月6日19:26:13 发表评论 675 次浏览

ftp_mdtm()函数是PHP中的内置函数, 用于获取上次修改FTP服务器上文件的时间。

语法如下:

ftp_mdtm( $ftp_connection, $file )

参数:此函数接受上述和以下所述的两个参数:

  • $ftp_connection:它是必填参数。它指定已经存在的FTP连接。
  • $file:它是必填参数。它指定远程服务器(即将检索其最后修改的FTP服务器)中的文件或文件的路径。

返回值:如果成功, 它将返回上次修改时间作为UNIX时间戳;如果错误, 则返回-1。

注意:

  • 此功能可用于PHP 4.0.0和更高版本。
  • 以下示例无法在在线IDE上运行。因此, 请尝试使用适当的ftp服务器名称在某些PHP托管服务器或localhost中运行。
  • 此功能不适用于目录。所有服务器可能不支持此功能。

例子:

<?php
   
// Connect to FTP server
   
// Use a correct ftp server
$ftp_server = "localhost" ;
   
// Use correct ftp username
$ftp_username = "user" ;
   
// Use correct ftp password corresponding
// to the ftp username
$ftp_userpass = "user" ;
  
// File name or path to upload to ftp server
$file = "demo_test.txt" ;
   
// Establishing ftp connection 
$ftp_connection = ftp_connect( $ftp_server ) 
         or die ( "Could not connect to $ftp_server" );
  
if ( $ftp_connection ) {
     echo "successfully connected to the ftp server!" ;
      
     // Logging in to established connection with
     // ftp username password
     $login = ftp_login( $ftp_connection , $ftp_username , $ftp_userpass );
      
     if ( $login ) {
          
         // Checking whether logged in successfully or not
         echo "<br>logged in successfully!" ;
          
         // Storing last modified data in $last_mod
         $last_mod = ftp_mdtm( $ftp_connection , $file );
          
         if ( $last_mod != -1) {
              
             // Checking whether any error occurred or not 
             // while retrieving last modified data
             echo "<br> $file was modified on " . 
                     date ( "F d Y H:i:s." , $last_mod ). "." ;
         }
         else {
             echo "<br>could not get last modified." ;
         }
           
     }
     else {
         echo "<br>login failed!" ;
     }
          
     // Closeing  connection
     if (ftp_close( $ftp_connection )) {
         echo "<br>Connection closed Successfully!" ;
     } 
}
?>

输出如下:

PHP ftp_mdtm()函数用法详细介绍

参考: https://www.php.net/manual/en/function.ftp-mdtm.php


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: