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

How to display attachments in external page

Discussion in 'XenForo Development Discussions' started by AndyB, Mar 27, 2013.

  1. AndyB

    AndyB Well-Known Member

    I have a mobile site that I wrote which is optimized for mobile users. When I display a thread in any post which has an attachment I parse the attachment code and replace it with HTML <img src> code to display the image, however this only works with the thumbnail images.

    The problem is that thumbnails images are very low resolution. What is the best way to display a full size attachment, I can't make the path to the full size attachments files because the extension used there is .data and will not display.

    Thank you.
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Refer to the bb_code_tag_attach template. This is the code for an inline full-sized attached image:

    <img src="{xen:link attachments, $attachment}" alt="{$attachment.filename}" class="bbCodeImage LbImage" />
    It uses xen:link to build a URL using the "attachments" route. It doesn't address the data file directly.
  3. AndyB

    AndyB Well-Known Member

    Hi Jake,

    Thank you for the above information.
  4. AndyB

    AndyB Well-Known Member

    I got a little further with my effort to display a full size attachment in an external page. If I use this code...

    header('Content-Type: image/jpeg');
    $get_image_data = file_get_contents('/home/path/to_my_file/forums/internal_data/attachments/0/1-b5b8dadf8a210bda593e1bde2abbfb7a.data');
    echo $get_image_data;
    ...it will display the image. Now to try and figure out how to use this code in a webpage along with text.
  5. Chris D

    Chris D XenForo Developer Staff Member

    Interesting route you're taking, despite Jake's advice.

    If the image you want to display in an external page has an attachment_id of 1 (which I think your code example above does based on the 1- prefix) then you need to do nothing more than this:

    <img src="http://your-site.com/attachments/1" />

    There's no need at all to interact with the raw data.
    Jake Bunce likes this.
  6. kingston

    kingston Well-Known Member

    Hi Jake. I am trying to teach myself more about how add-ons work in Xenforo. I have a custom add-on (and the author is currently unavailable for a while to make a change) where we are using an attachment from a post on another page. The author was pulling the thumbnail so the image is a very low resolution.

    <img src="{$item.thumbnailUrl}" alt="{$item.filename}" class="Thumbfeatured" data-src="{$item.filename}">
    What can I call to reference the full image itself and resize instead of just the thumbnail? The thumbnails are coming over at about 100x100 and I just need something 150x150 to look much better. Thanks for the help!

Share This Page