How can PHP scripts be modified to allow for the deletion of files and directories created by the script using FTP programs?
To allow for the deletion of files and directories created by a PHP script using FTP programs, you can modify the script to include FTP functions that connect to the server and delete the desired files and directories. This can be achieved by using PHP's built-in FTP functions like `ftp_connect`, `ftp_login`, `ftp_delete`, and `ftp_rmdir`.
<?php
// FTP server credentials
$ftp_server = 'ftp.example.com';
$ftp_user = 'username';
$ftp_pass = 'password';
// Connect to FTP server
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);
// Delete file
ftp_delete($conn_id, '/path/to/file.txt');
// Delete directory
ftp_rmdir($conn_id, '/path/to/directory');
// Close FTP connection
ftp_close($conn_id);
?>
Related Questions
- How can different browsers handle the downloading of PDF files generated with PHP?
- What potential pitfalls should be considered when implementing language selection functionality in PHP scripts?
- What are the benefits of using external configuration files for storing database connection details in PHP?