Change upload folder to a new host via ftp

we have a gravityform which has a multiple upload field
and want when user upload files the files upload to a second host via ftp connection
how can we implement this?

here what we do until now
the main site is mysite.com
and the subdomain which hosted on another hsoting is
files.mysite.com

add_filter( 'gform_upload_path', 'change_upload_path', 10, 2 );
function change_upload_path( $path_info, $form_id ) {
    // FTP credentials for host two
    $ftp_host = '****';
    $ftp_username = '***';
    $ftp_password = '***';
    
    // Remote path on host two where files should be uploaded
    $remote_path = '/public_html/guaranty_uploads/';
    
    // Connect to host two via FTP
    $ftp_connection = ftp_connect($ftp_host);
    ftp_login($ftp_connection, $ftp_username, $ftp_password);
    
    // Set the FTP upload directory on host two
    ftp_chdir($ftp_connection, $remote_path);
    
    // Update the path_info array with the FTP details
    $path_info['path'] = $remote_path;
    $path_info['url'] = 'http://files.mysite.com/guaranty_uploads/';
    $path_info['ftp_connection'] = $ftp_connection;
    
    return $path_info;
}

best regards

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.