PHP ftp_mdtm()Functions


PHP FTP 参考手册Complete PHP FTP Reference Manual

Definition and Usage

The ftp_mdtm() function returns the last modified time of a specified file.

This function will return the last modified time of the file in the form of a Unix timestamp, or -1 if an error occurs.

Syntax

int ftp_mdtm ( resource $ftp_stream , string $remote_file )

Parameters Description
ftp_connection Required. Specifies the FTP connection to log in.
file Required. Specifies the file to check.


Tips and Notes

Note:Not all FTP servers support this function.


Examples

<?php
$file = 'somefile.txt';

// 连接到服务器
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

//  获取最好修改时间
$buff = ftp_mdtm($conn_id, $file);
// 如果成功返回一个 UNIX 时间戳,否则返回 -1。
if ($buff != -1) {
    // 输出 somefile.txt 最后的修改时间
    echo "$file 最好修改时间为 : " . date ("F d Y H:i:s.", $buff);
} else {
    echo "无法获取文件的修改时间";
}

// 关闭连接
ftp_close($conn_id);
?>


PHP FTP 参考手册Complete PHP FTP Reference Manual Other Extensions