How can PHP be used to delete files uploaded via FTP?

To delete files uploaded via FTP using PHP, you can use the FTP functions provided by PHP. You can establish an FTP connection, navigate to the directory where the uploaded files are stored, and then use the ftp_delete() function to delete the files.

<?php
$ftp_server = "ftp.example.com";
$ftp_username = "username";
$ftp_password = "password";
$ftp_conn = ftp_connect($ftp_server);
$login = ftp_login($ftp_conn, $ftp_username, $ftp_password);

if ($login) {
    $file_to_delete = "example.txt";
    if (ftp_delete($ftp_conn, $file_to_delete)) {
        echo "File deleted successfully";
    } else {
        echo "Error deleting file";
    }
} else {
    echo "Failed to connect to FTP server";
}

ftp_close($ftp_conn);
?>