What is the significance of using absolute paths versus relative paths when specifying the destination folder in PHP FTP upload?

When specifying the destination folder in PHP FTP upload, using absolute paths ensures that the file is uploaded to the correct directory regardless of the current working directory. Relative paths, on the other hand, are dependent on the current working directory and may result in the file being uploaded to an unintended location. To avoid this issue, it is recommended to always use absolute paths when specifying the destination folder in PHP FTP upload.

// Absolute path example
$ftp_server = "ftp.example.com";
$ftp_user = "username";
$ftp_pass = "password";
$local_file = "local_file.txt";
$remote_file = "/path/to/destination_folder/remote_file.txt";

// Connect to FTP server
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);

// Upload file using absolute path
if (ftp_put($conn_id, $remote_file, $local_file, FTP_BINARY)) {
    echo "File uploaded successfully";
} else {
    echo "Failed to upload file";
}

// Close FTP connection
ftp_close($conn_id);