How can ftp_delete() be used to delete files from an FTP server in PHP?

To delete files from an FTP server in PHP, you can use the ftp_delete() function. This function requires an FTP connection to the server and the file path to be deleted. Once the file path is provided, ftp_delete() will attempt to delete the file from the server.

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

// Delete file from FTP server
$file_path = '/path/to/file.txt';
if (ftp_delete($conn_id, $file_path)) {
    echo "File deleted successfully.";
} else {
    echo "Error deleting file.";
}

// Close FTP connection
ftp_close($conn_id);