Latest web development tutorials

PHP ftp_mdtm () function

PHP FTP Reference Complete PHP FTP Reference

Definition and Usage

ftp_mdtm () function returns the specified file was last modified.

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

grammar

int ftp_mdtm ( resource $ftp_stream , string $remote_file )

参数 描述
ftp_connection 必需。规定要登录的 FTP 连接。
file 必需。规定要检查的文件。


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 Reference Complete PHP FTP Reference