1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Creating attachment from generated data

Discussion in 'XenForo Development Discussions' started by Teapot, Aug 18, 2013.

  1. Teapot

    Teapot Well-Known Member

    I could do with a little guidance from someone more familiar with the attachment system than me. Basically, I want to save an image I've generated programatically into the attachment system.

    The image itself is a fully-formed Imagick-generated PNG file, and can be downloaded directly from the controller. However, I'd like to allow the user to save it to the site to access later, and I'd ideally like to leverage the attachment system and all the various benefits it offers me over saving the image manually.

    Has anyone tried to use the attachment system this way? Is it feasible, and if so, where would you recommend I start?

    As always, thank you for your time.
     
  2. JulianD

    JulianD Well-Known Member

    I think attachments needs to be associated with a content type. Correct me if I'm wrong.
     
  3. AndyB

    AndyB Well-Known Member

    This is correct. So a new post would also need to be created so that you have a post number to associate the attachment to.
     
  4. Jeremy

    Jeremy XenForo Moderator Staff Member

    Attachments don't need to be associated with posts. They need to be associated with a content type, but it's not required to be posts (ie, conversation messages).
     
  5. digitalpoint

    digitalpoint Well-Known Member

    Yep... you can see how XenForo manages the attachment <-> content type relationship in the xf_content_type_field table. That's where you define the attachment handler class for the content type.

    You can also see how attachment handlers work by checking the library/XenForo/AttachmentHandler/ directory (that's where the handlers are for posts and conversations).
     

Share This Page