PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Attach a file from the Media Library

  1. I've just started using GravityForms, and am puzzled about how to attach a file to a user notification. I've been to the page describing gform_user_notification_attachments, but the example there is for attaching files just uploaded. What I want to do is to attach files that are in the media library.

    I created the following bit of code and inserted it into functions.php:

    add_filter("gform_user_notification_attachments_1", "add_attachment", 10, 3);
    function add_attachment($attachments, $lead, $form){
    	$attachments = array();
    	$attachments[] = '/wp-content/uploads/2013/02/digital-marketing-checklist-from-pv.pdf';
    	return $attachments;
    }

    Unfortunately, this isn't doing what I was hoping it would do, i.e. attach this file to the user notification. Do you have any idea what I'm doing wrong here?

    Also, I'd like to add some logic to download different files based on the value of one of the form fields. Can you give me a hint as to how to do that?

    Thanks, Dan

    Posted 11 years ago on Thursday February 21, 2013 | Permalink
  2. I think your path is probably wrong. Can you use the full path to the file on the server? I don't think (although I could be wrong) that wp-content is in the root directory of your web server. It should be a path more like /usr/local/apache/mysite/wordpress/wp-content/ etc. You are saying that wp-content is at the very root. I don't think that's correct, but I could be wrong.

    I haven't had a chance to look at that filter in depth, but it's also possible it's looking for a URL, so something more like http://www.example.com/wp-content/uploads/2013/02/digital-marketing-checklist-from-pv.pdf - can you try that as well?

    Posted 11 years ago on Saturday February 23, 2013 | Permalink