Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Quick help needed please!

    Hey guys,

    Just a quick one for you.. I'm using a WordPress plugin called Easy FTP Upload.. it basically has a form, where you enter your details, choose a file and submit.. the file is uploaded and I receive an email letting me know that the file has been uploaded.

    Now, I want the name, company name, telephone number, email, purpose of file and other notes to be included in the email. As far as I can see they are all set to be shown, however the name and company are not shown.. however, if I move say for example the company down a few lines it does show it, but then doesn't show the one above it.. So basically.. it's not outputting the first 2 variables.. I can't figure out why.. does anyone have an idea?


    PHP Code:
    <?php  
    /* 
    Plugin Name: Easy FTP Upload 
    Plugin URI: http://www.bucketofwombats.com/easy-ftp-upload-for-wordpress
    Description: Allows direct uploading via FTP from a page or post - good for larger files such as those needed by print shops and graphic designers
    Version: 2.7
    Author: Jenny Chalek 
    Author URI: http://www.bucketofwombats.com/
    */

    /*
    Easy FTP Upload plugin for WordPress
    Copyright 2011 Jenny Chalek (email:pandorawombat@gmail.com)

    This file is part of the Easy FTP Upload WordPress plugin.

    Easy FTP Upload is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or 
    any later version.

    Easy FTP Upload is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Easy FTP Upload.  If not, see <http://www.gnu.org/licenses/>.
    */

    //include_once 'Easy_FTP_htaccess.php'; //code to alter .htaccess to allow enough size for php temp files
    include_once 'Easy_FTP_Admin.php'//code for the options menu

    error_reporting(E_ERROR); //avoid displaying "warnings" that are irrelevant to end user

    //register_activation_hook(__FILE__, 'efu_alter_htaccess');

    add_action('wp_print_styles''efu_add_stylesheet');
    add_action('wp_print_scripts''efu_add_script');

    function 
    efu_add_stylesheet () {
        
    //load the .css file
        
    wp_register_style ('Easy_FTP_Upload_css''/wp-content/plugins/easy-ftp-upload/Easy_FTP_Upload.css');
        
    wp_enqueue_style ('Easy_FTP_Upload_css''/wp-content/plugins/easy-ftp-upload/Easy_FTP_Upload.css');
    }

    function 
    efu_add_script() {
        
    //load the .js file
        
    wp_register_script('easy_ftp_upload_js''/wp-content/plugins/easy-ftp-upload/Easy_FTP_Upload.js');
        
    wp_enqueue_script('easy_ftp_upload_js''/wp-content/plugins/easy-ftp-upload/Easy_FTP_Upload.js');
    }

    //register wp shortcode
    add_shortcode("easy_ftp_upload""efu_easy_ftp_upload_handler");

    //Main functions of the plugin
    //parse data from shortcode and assign defaults if necessary
    function efu_easy_ftp_upload_handler($atts) {
        
    shortcode_atts(array(
            
    'server' => '',
            
    'ftp_user_name' => '',
            
    'ftp_user_pass' => '',
            
    'notify_email' => ''
        
    ), $atts); //leave this loop here for later use possibly to make versions or something
            
        
    return efu_easy_ftp_upload_function();
        
    //send back data to replace shortcode in post
    }

    function 
    efu_upload_file_FTP ($server$ftp_user_name$ftp_user_pass$dest$source$client_dir)  {
        
    $ret_val ''//default return starting value assumes the worst
        //establish connection and login
        
        //connection moved to its own function to allow for multiple-format attempts
        
    $connection efu_connection($server);
        if (!
    $connection) return 'Connection attempt failed!'//end on failure
        
        //if no failure, then continue
        //login moved to its own function to allow for multiple-format attempts
        
    $login efu_login($connection$ftp_user_name$ftp_user_pass);
        
    //$login = ftp_login($connection, $ftp_user_name, $ftp_user_pass);

        
    if (!$login$ret_val 'Login attempt failed!';  //if failed to login both with and without domain name

        
    if (!$ret_val) {
            
    // turn passive mode on
            
    $success ftp_pasv($connectiontrue);
            if (!
    $success$ret_val 'Could not switch to passive mode!';
        }
        
        if (!
    $ret_val) {
            
    $ret_val_ch "";
            
    $duplicate false;
            
    $chmodYes =    chmod($client_dir0755); //first, try chmod before trying to access directory that may already exist
            
    if (!$chmodYes$ret_val_ch 'Could not chmod first pass.';
            
    $success ftp_chdir($connection$client_dir);
              if (!
    $success) { //if it fails to change dir, it probably doesn't exist, so create it
                  
    $success_make ftp_mkdir($connection$client_dir);
                  if (!
    $success_make$ret_val 'Could not create directory!'//if directory creation fails, program gracefully dies
              
    } else {
                  
    $duplicate true;
              }
              if (!
    $ret_val) {
                  
    $chmodYes chmod($client_dir0755); //try chmod directory before access - possibly redundant, but necessary for some servers
                  
    if (!$chmodYes$ret_val_ch .= 'Could not chmod second pass.';
                  if (
    $duplicate == false) { //avoid a second call to chdir, which could cause failure
                      
    $success ftp_chdir($connection$client_dir); //if success, now try to access the directory just made
                      
    if (!$success$ret_val 'Could not access directory!'//if directory access fails, program gracefully dies
                  
    }
              }
            if (!
    $ret_val) {//if no failure, then continue
                //set the permissions on the newly created directory, to avoid permission-based problems
                
    $chmodYes =    chmod($client_dir0755);
                if (!
    $chmodYes$ret_val_ch .= 'Could not chmod third pass.';
            
                
    //upload the file to the default directory
                
    $upload ftp_put($connection$dest$sourceFTP_BINARY);
                if (!
    $upload) {
                    
    $ret_val .= 'FTP upload failed! Sorry for any inconvenience - please contact us for assistance.';
                } else {
                    
    $ret_val 'FTP upload succeeded!';
                }
            }
        }
        
        
    //close the connection
        
    ftp_close($connection);
        
        return 
    $ret_val;
    }

    function 
    efu_filename_safe($filename) {
        
    $temp $filename;
        
        
    // Lower case
        
    $temp strtolower($temp);
        
        
    // Replace spaces with a '_'
        
    $temp str_replace(" ""_"$temp);
        
        
    // Loop through string, salvage only "safe" alphanumeric characters
        
    $result '';
        for (
    $i=0$i<strlen($temp); $i++) {
            if (
    preg_match('([0-9]|[a-z]|_)'$temp[$i])) {
                
    $result $result $temp[$i];
            }
        }

        
    // Return filename
        
    return $result;
    }

    function 
    efu_connection($server) {
        
    $connection ftp_connect($server'21'); //attempt #1, root domain only
        
    if ($connection) return $connection//return ftp stream if it worked
        
        
    $connection ftp_connect($server); //attempt #2, root domain without forced port
        
    if ($connection) return $connection//return ftp stream if it worked
        
        //keep going otherwise
        
    $tryThis "ftp.".$connection;
        
    $connection ftp_connect($tryThis'21');
        if (
    $connection) return $connection//return ftp stream if it worked

        //keep going otherwise
        
    $connection ftp_connect($tryThis); //no forced port
        
    if ($connection) return $connection//return ftp stream if it worked
        
        //keep going otherwise
        
    $tryThis "www.".$connection//our last 2 attempts
        
    $connection ftp_connect($tryThis'21');
        if (
    $connection) return $connection//return ftp stream if it worked

        //keep going otherwise
        
    $connection ftp_connect($tryThis); //last try, no port
        
        
    return $connection//returns ftp stream if it worked or false if not
    }

    function 
    efu_login($connection$ftp_user_name$ftp_user_pass) {
        
    $login ftp_login($connection$ftp_user_name$ftp_user_pass);
        if (!
    $login) { //if the login fails initially, try again after stripping off any domain name at the end
            
    $login ftp_login($connectionefu_username_scrub($ftp_user_name), $ftp_user_pass);
        }
        return 
    $login//return the final result whether successful or not
    }

    function 
    efu_domain_scrub($server) {
        
    $strWork trim(strtolower($server)); //convert to lowercase
        
        
    if (substr($strWork04) == "http") {
            
    $strWork substr($strWork,4); //strip http if it's there
        
    }
        
    $strWork trim($strWork,"/"); //trim off any leading or training slash marks
        
    if (substr($strWork04) == "www.") {
            
    $strWork substr($strWork,4); //strip www. if it's there
        
    }
        if (
    substr($strWork04) == "ftp.") {
            
    $strWork substr($strWork,4); //strip ftp. if it's there
        
    }
        
    // Return stripped-down domain name
        
    return $strWork;
    }

    function 
    efu_username_scrub($username) {
        
    $whereAt stripos($username"@");
        if (
    $whereAt) { //if the character @ is found, strip off domain name
            
    $username substr($username0$whereAt);
        }
        return 
    $username;
    }

    function 
    efu_easy_ftp_upload_function() {
        
    //if this is AFTER the POST action, proceed to actual data parse, upload, etc.
        
    if (!empty($_POST)) {
            return 
    efu_easy_ftp_upload_post();
        } else { 
    //otherwise, link to and load the html form
            
    ob_start();
            include(
    'Easy_FTP_Upload.html');
            
    $web_form ob_get_clean();
            return 
    $web_form;
        }
    }

    function 
    efu_easy_ftp_upload_post() {
        
    //gather data from saved settings and assign to variables    
        
    $atts get_option('efu_plugin_options');
        
    $server $atts['efu_server'];
        
    $ftp_user_name $atts['efu_username'];
        
    $ftp_user_pass $atts['efu_user_pass'];
        
    $notify_email $atts['efu_notify'];
        
        
    //gather data from form post and assign to variables
        
    $company $_POST['company_name'];
        
    $contact $_POST['contact_name'];
        
    $telephone $_POST['telephone_number'];
        
    $email_add $_POST['email_add'];
        
    $purpose $_POST['purpose']; //radio button to choose whether file is for quote or live job or other
        
    $notes $_POST['notes'];
        
        
    //parse name for client directory - favor company name, but use contact name if none
        
    if (!$company$who_is $contact;
        else 
    $who_is $company;
        
    //must convert the client name to something filename safe to create directory
        
    $client_dir efu_filename_safe($who_is);
        
        
    $source $_FILES['file']['tmp_name']; // retrieve name of the source file to be uploaded
        
    $dest $_FILES['file']['name'];
        
    // call the upload function itself , gather back success or failure message
        
    $successful efu_upload_file_FTP($server$ftp_user_name$ftp_user_pass$dest$source$client_dir);
        
        
    // construct the email notification data
        
    if ($successful == 'FTP upload succeeded!') {
            
    $notifysubject 'FTP Upload Notification'//successful upload
        
    } else $notifysubject 'FTP Upload Failed: Contact Client!'//failed upload - need to contact client
        
        
    $notifymessage 'Contact Name: '.$contact.PHP_EOL;
        
    $notifymessage 'Company: '.$company.PHP_EOL;
        
    $notifymessage 'Telephone Number: '.$telephone.PHP_EOL;
        
    $notifymessage .= 'Email Address: '.$email_add.PHP_EOL;
        
    $notifymessage .= 'Purpose of File: '.$purpose.PHP_EOL;
        
    $notifymessage .= 'Other Notes or Instructions: '.$notes;
        
        
    $notifyheader 'From: Uploads <'.$email_add.'>'.PHP_EOL;
        
        
    // call the email notification function with required arguments
        
    $mail_sent wp_mail($notify_email$notifysubject$notifymessage$notifyheader);
        If (
    $mail_sent) {
            
    $successful .= '<br/>Notification email sent.';
        } else {
            
    $successful .= '<br/>Notification email failed to send!'.PHP_EOL;
            
    $successful .= 'Even if your file uploaded successfully, '.PHP_EOL;
            
    $successful .= 'for the sake of expediency you may wish '.PHP_EOL;
            
    $successful .= 'to contact us and alert us to your upload.'.PHP_EOL;
        }
        return 
    '<br/><p class="EFU_notify">'.$successful.'</p>';
    }
    ?>
    Thanks SO much in advance!

  2. #2
    Supreme Master coder!
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    10,055
    Thanks
    10
    Thanked 1,156 Times in 1,147 Posts
    I'm guessing the FTP uploader is used to upload files (via FTP, File Transfer Protocol).

    You need a plugin for handling forms ... like this:
    http://contactform7.com/


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •