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);
?>
Keywords
Related Questions
- How can one effectively utilize PHP forums and subforums to seek assistance with PHP-related database issues?
- How can the PHP script be modified to accurately display the online and offline status of servers, especially when dealing with different protocols like UDP?
- What are common reasons for a PHP variable not being passed correctly to an object method?