How can PHP be used to list files in an FTP directory and highlight files older than a day in red?

To list files in an FTP directory using PHP, you can use the FTP functions provided by PHP. To highlight files older than a day in red, you can compare the file's last modification timestamp with the current time and apply a CSS style to those files. You can achieve this by retrieving the file information using FTP functions, comparing the timestamps, and then outputting the file list with appropriate styling.

<?php
// Connect to FTP server
$ftp_server = 'ftp.example.com';
$ftp_user = 'username';
$ftp_pass = 'password';
$conn_id = ftp_connect($ftp_server);
ftp_login($conn_id, $ftp_user, $ftp_pass);

// Get list of files in FTP directory
$files = ftp_nlist($conn_id, '/path/to/directory');

// Loop through files and highlight files older than a day in red
foreach ($files as $file) {
    $file_time = ftp_mdtm($conn_id, $file); // Get file modification time
    $current_time = time();
    $day_seconds = 24 * 60 * 60; // Number of seconds in a day

    if (($current_time - $file_time) > $day_seconds) {
        echo '<span style="color: red;">' . $file . '</span><br>';
    } else {
        echo $file . '<br>';
    }
}

// Close FTP connection
ftp_close($conn_id);
?>