PHP ftp_mdtm() Function
Example
Get last modified time for a file on the FTP server:
<?php
// connect and login to FTP server
 $ftp_server = "ftp.example.com";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
$file = "somefile.txt";
 
// get the last modified time
$lastchanged = ftp_mdtm($ftp_conn, $file);
if ($lastchanged != -1)
  {
  echo "$file was last modified on : " . date("F d Y H:i:s.",$lastchanged);
  }
 else
  {
  echo "Could not get last modified";
  }
 
// close connection
ftp_close($ftp_conn);
?>
Definition and Usage
The ftp_mdtm() function returns when the specified file was last modified.
Note: Not all servers support this function, and this function does not work with directories.
Syntax
ftp_mdtm(ftp_conn, file);
Parameter Values
| Parameter | Description | 
|---|---|
| ftp_conn | Required. Specifies the FTP connection to login to | 
| file | Required. Specifies the file to check | 
Technical Details
| Return Value: | The last modified time as a Unix timestamp on success, -1 on failure | 
|---|---|
| PHP Version: | 4+ | 
❮ PHP FTP Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.