What are the best practices for handling file uploads through forms in PHP to ensure the full file path is included for successful FTP uploads?

When handling file uploads through forms in PHP, it is important to ensure that the full file path is included for successful FTP uploads. This can be achieved by using the $_FILES superglobal array to retrieve the temporary file location, and then using the move_uploaded_file function to move the file to the desired FTP server location.

<?php
// Check if the file was uploaded successfully
if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
    $tempFile = $_FILES['file']['tmp_name'];
    $ftpServer = 'ftp.example.com';
    $ftpUsername = 'username';
    $ftpPassword = 'password';
    $ftpFilePath = '/path/to/ftp/directory/' . $_FILES['file']['name'];

    // Connect to FTP server
    $ftpConnection = ftp_connect($ftpServer);
    ftp_login($ftpConnection, $ftpUsername, $ftpPassword);

    // Upload file to FTP server
    if (ftp_put($ftpConnection, $ftpFilePath, $tempFile, FTP_BINARY)) {
        echo 'File uploaded successfully';
    } else {
        echo 'Failed to upload file';
    }

    // Close FTP connection
    ftp_close($ftpConnection);
} else {
    echo 'Error uploading file';
}
?>