THE WORLD'S LARGEST WEB DEVELOPER SITE

PHP ftp_mdtm() Function

❮ PHP FTP Reference

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 on directories.

Syntax

ftp_mdtm(ftp_connection,file);

Parameter Description
ftp_connection Required. Specifies the FTP connection to login to
file Required. Specifies the file to check

Technical Details

Return Value: Returns the last modified time as a Unix timestamp, or -1 on error
PHP Version: 4+

❮ PHP FTP Reference