共計 793 個字符,預計需要花費 2 分鐘才能閱讀完成。
在 PHP 中,可以使用 ftp_mdtm() 函數獲取指定文件的修改時間。該函數的用法如下:
int ftp_mdtm (resource $ftp_stream , string $remote_file)
參數說明:
ftp_stream:FTP 連接資源(使用ftp_connect()函數創建)。remote_file:遠程文件路徑。
返回值:
- 成功時,返回文件的修改時間(UNIX 時間戳格式)。
- 失敗時,返回 false。
示例代碼:
$ftp_server = 'example.com';
$ftp_username = 'username';
$ftp_password = 'password';
// 連接 FTP 服務器
$ftp_conn = ftp_connect($ftp_server);
if (!$ftp_conn) {die("無法連接到 FTP 服務器");
}
// 登錄 FTP 服務器
$login_result = ftp_login($ftp_conn, $ftp_username, $ftp_password);
if (!$login_result) {die("登錄失敗");
}
$remote_file = '/path/to/file.txt';
// 獲取文件的修改時間
$modification_time = ftp_mdtm($ftp_conn, $remote_file);
if ($modification_time !== false) {echo "文件的修改時間:", date('Y-m-d H:i:s', $modification_time);
} else {echo "無法獲取文件的修改時間";}
// 關閉 FTP 連接
ftp_close($ftp_conn);
注意:在使用 ftp_mdtm() 函數前,需要首先通過 ftp_connect() 函數連接 FTP 服務器,然后使用 ftp_login() 函數登錄 FTP 服務器。
丸趣 TV 網 – 提供最優質的資源集合!
正文完