CF7 Form File Upload to FTP Servers Based on Dropdown Selection

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** – Orange Facility
ftp** – Anaheim Facility

Here’s the code:


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_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.";
     // echo "Error uploading $fileToUpload.";
    // close connection


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

Leave a Reply

Your email address will not be published. Required fields are marked *