• In the codex, it says that wp_insert_attachment() needs the $filename to be the absolute path to the uploaded file.

    On my website, I am using Gravity Forms form to receive file uploads and the form entry returns the URI of the file, not its path.

    I noticed that creating an attachment with URI is working fine for me and also saw in the codex page, that the guid of the file in the example is a URI and not a path.

    So, is it ok to use URI or am I missing something? because I have a feeling that I do…

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Yes, it does work, but no, it’s not OK. The ultimate goal is to store the relative path from wp-content. When you provide an URL instead, the entire URL is stored instead of a relative path. The URL still retrieves the file, but such a request is nowhere near as efficient as a relative file system request. You will not notice a significant difference on a small site, but a large heavily used site can be brought down by providing URLs instead of paths.

    There must be some way of getting a path from Gravity forms, but I don’t know enough about them to suggest anything. As long as your site doesn’t grow significantly you can probably get by without addressing this issue.

    Thread Starter rechazame

    (@rechazame)

    Got it. I will make the necessary changes.

    And regarding the ‘guid’, why then does it use the URL in the codex example?

    Moderator bcworkz

    (@bcworkz)

    The GUID field is a completely separate data entity where the actual URL is stored. While there is obviously a relationship to the filename path, in an abstracted sense, it can be considered to be unrelated. The path has certain uses, and the URL has other uses. It’s useful to not need to convert between the two reference types.

    I’m not sure how WP actually uses GUID, but I have found the GUID data to be convenient to use on occasion, so I’m glad it’s there ??

    Thread Starter rechazame

    (@rechazame)

    Ok, nice ??

    I will try take it from here, though the whole PATH vs URL still confuses me sometimes. Even after reading half of Google ??

    Thx for your help buddy.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_insert_attachment Deals Just Fine With URI’ is closed to new replies.