How can one modify a PHP script to enable file uploads via FTP instead of storing them locally?
To modify a PHP script to enable file uploads via FTP instead of storing them locally, you can use the FTP functions provided by PHP to connect to an FTP server and upload the files. This allows you to store the files on a remote server instead of on the local server where the PHP script is running.
<?php
$ftp_server = "ftp.example.com";
$ftp_username = "username";
$ftp_password = "password";
$local_file = "local_file.txt";
$remote_file = "remote_file.txt";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_password);
if (ftp_put($ftp_conn, $remote_file, $local_file, FTP_ASCII)) {
echo "File uploaded successfully!";
} else {
echo "Failed to upload file!";
}
ftp_close($ftp_conn);
?>