XF 1.1 Force certain attachment to view/open directly on the browser instead of downloading it


Well-known member
Just like image(jpg,png,gif) attachment, if you click them on the attachment, you can view it directly.
So I want certain extension also, like .txt to open directly on the browser when click not to download.

How can I do that?

Jake Bunce

XenForo moderator
Staff member


Well-known member
That is up to the client browser. You can only control your own browser settings.
Not necessarily. This is where MIME come into play, specifically the Content-Disposition and Content-Type headers.

For example, depending on your installed PDF viewer,

Content-Disposition: inline; filename="document.pdf"

will open the PDF inline for viewing inside the browser window. Whereas

Content-Disposition: attachment; filename="document.pdf"

will inform the browser that the PDF should be saved as a file instead. Sure, ultimately it depends on your client and what apps you have installed on your client computer, but there is at least a way to hint the browser of how the file should be opened/downloaded. Not every browser behaves the same, and here is a (somewhat outdated) list with example links of how browsers react to sending inline txt content:



Well-known member
You do this via http headers. Either in your webserver configuration, if you have access, or via software. Unlike vBulletin, xF doesn't allow to change mime settings for individual attachment types, so that would require an add-on.


Is there a way to force a link to a file in a post to download rather than view inline?

I am helping a client on XF 1.4 to create a link to a PDF within a post and make the default link behavior to download the file.

I know that adding it as an attachment will accomplish this but he wants to do it in the post.