How can the value of $source_file be correctly assigned in a PHP script for uploading files via FTP?

When uploading files via FTP in PHP, the value of $source_file should be assigned the correct file path of the file you want to upload. This can be done by using the $_FILES superglobal array to get the temporary location of the uploaded file and then moving it to the desired destination.

$source_file = $_FILES['file']['tmp_name'];
$destination_file = '/path/to/destination/file.txt';

$ftp_server = 'ftp.example.com';
$ftp_username = 'username';
$ftp_password = 'password';

$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_username, $ftp_password);

if (ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY)) {
    echo "File uploaded successfully";
} else {
    echo "Failed to upload file";
}

ftp_close($conn_id);