What could be causing the error message "connection established but image upload failed" in a PHP script using FTP functions?

The error message "connection established but image upload failed" in a PHP script using FTP functions could be caused by incorrect file permissions, incorrect file path, or insufficient server disk space. To solve this issue, make sure the file path is correct, check and adjust file permissions if needed, and ensure there is enough disk space on the server for the image upload.

<?php
$ftp_server = "ftp.example.com";
$ftp_username = "username";
$ftp_password = "password";
$local_file = "local_image.jpg";
$remote_file = "remote_image.jpg";

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

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

if (ftp_put($conn_id, $remote_file, $local_file, FTP_BINARY)) {
    echo "Image uploaded successfully!";
} else {
    echo "Image upload failed!";
}

ftp_close($conn_id);
?>