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

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

RoldanLT

Well-known member
#1
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
#4

AlexT

Well-known member
#6
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:

http://perlpunks.de/deliver_html_as_text_plain.html
 

AlexT

Well-known member
#8
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.
 
#12
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.

Thanks.