ftp_mdtm()函数是用来获取指定文件的修改时间的。它的基本语法如下:
int ftp_mdtm ( resource $ftp_stream , string $remote_file )其中,$ftp_stream是一个已经通过ftp_connect()函数连接到FTP服务器的资源句柄,$remote_file是要获取修改时间的远程文件名。
下面是一个示例,演示如何使用ftp_mdtm()函数获取指定文件的修改时间:
<?php// 连接到FTP服务器$ftp_server = 'ftp.example.com';$ftp_user = 'username';$ftp_password = 'password';$conn_id = ftp_connect($ftp_server);$login_result = ftp_login($conn_id, $ftp_user, $ftp_password);// 获取文件的修改时间$remote_file = 'example.txt';$modification_time = ftp_mdtm($conn_id, $remote_file);if ($modification_time != -1) { echo "The modification time of $remote_file is " . date('Y-m-d H:i:s', $modification_time);} else { echo "Failed to retrieve the modification time of $remote_file";}// 关闭FTP连接ftp_close($conn_id);?>首先,我们使用ftp_connect()函数连接到FTP服务器,并使用ftp_login()函数进行登录验证。
然后,我们指定要获取修改时间的远程文件名。
接下来,我们调用ftp_mdtm()函数,传入连接资源句柄和远程文件名,获取文件的修改时间。
最后,我们通过判断返回的修改时间是否为-1,来确定是否成功获取到修改时间。如果获取成功,我们使用date()函数将修改时间格式化,并输出到屏幕上。否则,我们输出错误信息。
最后,我们使用ftp_close()函数关闭FTP连接。
这就是使用ftp_mdtm()函数获取指定文件修改时间的示例。

