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.

Adding filesize to admin notification email.

  1. Hi all,
    I am posting here to see if any of you can help with my problem. I have a client who would like to receive the file size of uploaded images directly in the admin notification email after a form submission.

    I have done the following: I added a hidden 'File Size' field on the form. I also added an addaction for gform_pre_submission. This is shown in the pasted code. So my plan here is inside the function that is called by the gform_submission I will had a php filesize to get the size in bytes of that file, and then change the value of the filesize input.

    My problem is I can not for the life of my figure out how to get the URL of the file inside this function. I figured out how to do it in the gform_post_submission hook, but by this hook the email has all ready sent :/ . I feel there must be a way to do this since the email sends a link directly to the file, i just cant find out where this is happening. Any suggestions here? Much appreciated in advance.

    //Gravity Forms include File Size In Admin Notification Email
    add_action("gform_pre_submission", "pre_submission_handler");
                    function pre_submission_handler($entry, $form){
                    /*
                    How Do I Get $url here?
    
                    $fileSize = filesize($url);
                    if ($fileSize < 1024) {
            echo $fileSize .' B';
                    } elseif ($fileSize < 1048576) {
                            echo round($fileSize / 1024, 2) .' KB';
                    } elseif ($fileSize < 1073741824) {
                            echo round($fileSize / 1048576, 2) . ' MB';
                    }*/
                            $_POST['input_22'] = 'SizeHere';
                    }
    
    //This is the working hook/filter, its just too late to change the field name since the file has all ready been sent.
    add_action("gform_post_submission", "post_sendmail_handler", 10, 2);
                    function post_sendmail_handler($entry, $form){
                            $url = $entry[2];
    
                    }
    Posted 12 years ago on Friday May 18, 2012 | Permalink
  2. David Peralty

    You should be able to get it via the Post variable and its field ID like what is in the documentation page:
    http://www.gravityhelp.com/documentation/page/Gform_pre_submission

    Posted 12 years ago on Friday May 18, 2012 | Permalink
  3. When I do a print_r($_POST) I see no variables that have a link as a value. I see what appears to be two encrypted looking values which are as follows which I suspect may be the link? :
    [gform_unique_id] => 4fbbd018c285b [state_3] => YToyOntpOjA7czo2OiJhOjA6e30iO2k6MTtzOjMyOiIwY2U0NGU1ZjQxZDdkYmM4MGMwMzlmOTg0OTk1NWY3ZCI7fQ==

    Is there an example of code you can provide that shows how to get the link inside of this pre_submission hook? Thanks again!

    Posted 12 years ago on Tuesday May 22, 2012 | Permalink
  4. Any update on this? I am a little stranded right now :/

    Posted 11 years ago on Tuesday May 29, 2012 | Permalink
  5. David Peralty

    Sorry, you can't get the size of the file because it isn't uploaded until the form is submitted. This hook might help though:

    http://www.gravityhelp.com/documentation/page/Gform_entry_created

    It is fired after the lead has been created, but before the post has been created, notifications have been sent and the confirmation has been processed.

    Posted 11 years ago on Wednesday May 30, 2012 | Permalink
  6. Awesome, that hook worked great. One last step in this process though. From here I can get the file size. Now all i need to do is add that file size to the hidden field (aka $entry[22]), I try to do so by the following gravity form function: ($contentLength is declared right before this, and outputs itself as an int, hence the string conversion)

    gform_update_meta($entry[22], '22' , (string)$contentLength);

    This doesnt seem to do anything, yet I believe its all in the correct format.
    I also went to the form itself and checked off "Allow field to be populated dynamically" and put "contentLength" as the parameter(is this the correct procedure?) . Any insight would be great! Thanks again for the help so far / in advance

    Posted 11 years ago on Friday June 1, 2012 | Permalink
  7. Sorry to ask again, but I am still waiting on an answer on this. Much appreciated in advance :)

    Posted 11 years ago on Wednesday June 6, 2012 | Permalink
  8. David Peralty

    I think you want something more like:
    gform_update_meta($entry['id'], "contentlength", $contentLength);
    You want it to be: Entry ID, Meta Key, New Value.

    Posted 11 years ago on Wednesday June 6, 2012 | Permalink