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.

Manipulating URL of uploaded file

  1. Hello,

    how can I get a hold of the URL of an uploaded file in order to do something with that URL?

    Say, the file upload field ID is 21. I've tried accessing the URL via $_FILES['input_21'] but didn't succeed. Also, which hook do I have to use?

    It'd be great if you could point me to an example.

    Thank you.
    Marc.

    Posted 12 years ago on Monday May 28, 2012 | Permalink
  2. David Peralty

    What are you trying to do with that URL? Here is the File Upload Path hook:
    http://www.gravityhelp.com/documentation/page/Gform_upload_path

    Posted 12 years ago on Monday May 28, 2012 | Permalink
  3. David, thanks, as always, for your reply.

    I'm trying grab that URL to pass it to the Embed.ly API to generate the embed code for resizing and including that photo in a post.

    Also, can you point me to a good way of automatically reducing files in size?

    Marc
    Miami

    Posted 12 years ago on Monday May 28, 2012 | Permalink
  4. On the page of the link you sent me, the example seems to be about changing the upload path; I'd like to just know what the URL is; no need to change it. Thanks again.

    Posted 12 years ago on Monday May 28, 2012 | Permalink
  5. David Peralty

    Ah, sorry. I assumed you wanted to change the URL of where a file was uploaded.

    Using the http://www.gravityhelp.com/documentation/page/Gform_after_submission hook and the Field ID - $field[1]; you should be able to get the file URL.

    This is the same hook to pass data to a third party site.

    As for re-sizing and whatnot, there are lots of PHP scripts relating to that as well.

    Posted 12 years ago on Monday May 28, 2012 | Permalink
  6. David, I tried the code below, but I'm still doing something wrong.

    21 is the ID of the hidden field I want to pass the URL on to. The file upload field's ID is 20. The form's ID is 12. By the way, what is the role of the arguments "10,2"?

    Thanks for your help.

    Marc

    code I'm using:

    add_action("gform_after_submission_12", "get_url", 10, 2);
    function geturl($form) {
    $_POST['input_21'] = $field[20];
    }

    Posted 12 years ago on Monday May 28, 2012 | Permalink
  7. I noticed my function name was missing the underscore. I fixed that, but it's still not working:

    add_action("gform_after_submission_12", "get_url", 10, 2);
    function get_url($form) {
    $_POST["input_21"] = $field[20];
    }

    Posted 12 years ago on Monday May 28, 2012 | Permalink
  8. David Peralty

    You can't add it to the field because this hook is after the form has already been submitted (you have to wait until the form is submitted because that's when the file is actually uploaded to your server). You should just grab it and pass it right to the Embed.ly API.

    Posted 12 years ago on Monday May 28, 2012 | Permalink
  9. David, I need to display the results from the Embedly call inside the post that is being created. GF displays the URL fine if I just add "{File:20}" inside the "Post Body" container in the GF backend interface. There must be a way to get the URL just before GF puts it inside the post, run it through the function that produces the embed code, and display that instead...

    (Just FYI, I'm basically wanting to allow a user to upload an image and display it inside the post with a max-width attribute - in case you can point me to different way of accomplishing that).

    Thank you.
    Marc.

    Posted 12 years ago on Monday May 28, 2012 | Permalink
  10. I realized I can just hardcode something like the code below into the GF Post Body container. Duh. Thank you.

    <img src="{File:20}" alt="" style = "max-width:590px"/>

    Posted 12 years ago on Monday May 28, 2012 | Permalink
  11. David Peralty

    Glad you were able to figure it out. :)

    Posted 12 years ago on Monday May 28, 2012 | Permalink