WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
[resolved] upload file to wordpress folder before send email (9 posts)

  1. emile13
    Member
    Posted 3 years ago #

    hi

    i'm using the function
    add_action( 'wpcf7_before_send_mail', 'contactform7_before_send_mail' );

    to create a post in wordpress with the data of contact form 7

    i whant to upload a file to my wp-content/uploads/ but when i do this

    $file= $cf7->posted_data["file"];
    i have just the name of the file and not the original directory (ex :c:\Users\documents\myfile.jpg

    do you have an idee how can i proccess?

    thanks

    http://wordpress.org/extend/plugins/contact-form-7/

  2. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 3 years ago #

    The $cf7->posted_data parameter only has file names. Use $cf7->uploaded_files instead, as it is an array of {field name => file path}. So when the field name is 'file', you can get the file path by $cf7->uploaded_files["file"].

  3. emile13
    Member
    Posted 3 years ago #

    thanks so much you save my day

  4. mrjak01
    Member
    Posted 3 years ago #

    @ emile13

    Hello,

    Is this correct? Your code is sending the email and uploaded file notification to the email recipient but also the file is being uploaded to a permanent directory?

    Can you please explain the process? I would like to set this up for myself.

    Thank you

  5. emile13
    Member
    Posted 3 years ago #

    yes it's the idea

    i use it for concerts events

    a visitor add an events and i create a post to draft and i have just to publish it after

    save time, save money

  6. mrjak01
    Member
    Posted 3 years ago #

    ...

    Are uploaded images going into a static folder though? If so, how do you have that set up?

  7. emile13
    Member
    Posted 3 years ago #

    yes it's the idea upload the images in uploads directory, create thumbail and set as featured image

    you can look here the final code

    http://seodebutant.com/2011/08/16/poster-directement-un-evenement-dans-events-calendar-pro-via-contact-form-7/

  8. jsims281
    Member
    Posted 2 years ago #

    I use this code to move my uploaded files into the uploads folder before cf7 gets chance to delete them. I also add a random string to the start of the filename so that there is almost no risk of duplicated file names.

    function update_event(){
        $random = date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000)).rand(0,10000);
    
        $eventImgClean = "/".$random.str_replace("/home/website/public_html/wp-content/uploads/wpcf7_uploads/","",$cf7->uploaded_files['event-image']);
        $eventImg = $cf7->uploaded_files['event-image'];
        if (strlen($eventImg)<1)  {
          $eventImg = FALSE;
        }
        else {
          //make sure the image is below 1Mbyte
          if (filesize($eventImg) < 1048576){
            copy($eventImg, "wp-content/uploads/".$eventImgClean);
            $evImg = "/wp-content/uploads/".$eventImgClean;
            $filesize1_ok = TRUE;
          } else {
            $filesize1_ok = FALSE;
          }
        }
        //do extra stuff here
    }
    
    add_action('wpcf7_before_send_mail', 'update_event');
  9. atomik
    Member
    Posted 2 years ago #

    Great shot!
    Gonna try it asap.
    Thx

    -m.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic