What potential issues can arise when deleting data from an FTP server using PHP?
When deleting data from an FTP server using PHP, potential issues can arise if the file path is not properly specified, leading to unintended deletion of files. To solve this, it is important to double-check the file path before executing the delete operation to ensure that the correct file is being targeted.
<?php
$ftp_server = 'ftp.example.com';
$ftp_user = 'username';
$ftp_pass = 'password';
$file_path = '/path/to/file.txt';
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);
if (ftp_delete($conn_id, $file_path)) {
echo "File deleted successfully";
} else {
echo "Error deleting file";
}
ftp_close($conn_id);
?>