What are common errors encountered when using ftp_put in PHP for file uploads?

One common error encountered when using ftp_put in PHP for file uploads is incorrect file paths or permissions. Make sure that the file path is accurate and that the directory on the FTP server has the necessary write permissions. Another common error is not handling errors properly, such as checking if the file was uploaded successfully.

// Connect to FTP server
$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);

// Check if connection is successful
if (!$conn_id || !$login_result) {
    die("FTP connection failed");
}

// Upload file
$local_file = "local_file.txt";
$remote_file = "remote_file.txt";
if (ftp_put($conn_id, $remote_file, $local_file, FTP_ASCII)) {
    echo "File uploaded successfully";
} else {
    echo "Error uploading file";
}

// Close FTP connection
ftp_close($conn_id);