I have a simple request form setup in Contact Form 7 with a dropdown selection of two facilities. There are two anonymous server addresses to upload files to based on which dropdown facility is selected. I have successfully added the following code to the functions.php file, tested it and it works correctly for one of the dropdown selections. My problem is, I cannot get the code right for the other dropdown selection to upload and work correctly.

The setup is the form part goes to a distributed email address and the file gets uploaded to the Anaheim or Orange FTP server.

ftp**.domain.com – Orange Facility
ftp**.domain.com – Anaheim Facility

Here’s the code:

<?php

add_action('wpcf7_before_send_mail', 'log_cf7');
function log_cf7($WPCF7_ContactForm) {
    $submission = WPCF7_Submission::get_instance();
    $data = $submission->get_posted_data();
    $uploadedFiles = $submission->uploaded_files();

    $location = $data['SelectAFacility'];
    if(isset($uploadedFiles) && isset($uploadedFiles['your-file'])){
    $ftp_server="ftp**.domain.com";
    $ftp_username="username";
    $ftp_userpass="password";
    $ftp_conn = ftp_connect($ftp_server) or die("Could not connect to server");
    $login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);

    $fileToUpload =     $uploadedFiles['your-file'];
    $remotefile = $_FILES['your-file']['name'];

      if (ftp_put($ftp_conn, $remotefile, $fileToUpload, FTP_ASCII))
    {
      //echo "Successfully uploaded $remotefile.";
  }
      else
    {
     // echo "Error uploading $fileToUpload.";
  }
    // close connection
    ftp_close($ftp_conn);
  }

}

This only works for the Orange Facility. Now I can’t seem to get the logic right for the 2nd code. Any help?

Read more here: CF7 Form File Upload to FTP Servers Based on Dropdown Selection


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: