Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-10-15 11:06:47

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 535

Force a web browser to open or save files rather than auto download

Is this the correct place to ask server related questions?

Is there a way I can force all web browsers to prompt a user to either Open or Save As… a file (such as MS Office documents) rather than it be automatically download? I was wondering if this could be accomplished using using .htaccess?

The problem is most Chromium based browsers (I’m looking at you Google Chrome) automatically downloads the file. One of our non Textpattern systems allows users to upload documents to a VLE to be viewed online. Every time someone clicks a document link it downloads a copy to their network space. I’ve repeatedly asked the users to remove old files but they never do and eventually run out of disk space. This is usually followed up by a call to the IT Department to complain that the system is at fault and needs to be fixed.

Offline

#2 2020-10-15 11:15:43

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: Force a web browser to open or save files rather than auto download

HTML 5’s a tag has a download attribute which purports to force the browser to download rather than follow the link.

It may be possible to hijack this functionality with a suitable download attribute in our <txp:file_download_link> tag suite to factor this in. That way, you could force a download by adding that attribute to the tag, and internally we’d change the anchor to add download to it. By defaut that would use the given filename, but if you specified a value in the download attribute, we could pass that along instead.

Would that be useful? Anyone see any pitfalls?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2020-10-15 11:32:14

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Force a web browser to open or save files rather than auto download

Bloke wrote #326404:

Anyone see any pitfalls?

I’m afraid this will not suffice for files served by txp, since we set Content-Disposition attribute, and

if the Content-Disposition header has different information from the download attribute, resulting behaviour may differ:

If the header specifies a filename, it takes priority over a filename specified in the download attribute.

If the header specifies a disposition of inline, Chrome, and Firefox 82 and later, prioritize the attribute and treat it as a download. Firefox versions before 82 prioritize the header and will display the content inline.

Offline

#4 2020-10-15 11:36:42

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: Force a web browser to open or save files rather than auto download

Drat.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2020-10-15 11:39:30

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Force a web browser to open or save files rather than auto download

If this can help: etc_output_file.

Offline

#6 2020-10-15 11:45:24

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Force a web browser to open or save files rather than auto download

Though the question seems to be rather browser than txp-related.

Offline

#7 2020-10-15 12:48:53

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,134
GitHub

Re: Force a web browser to open or save files rather than auto download

Could you bludgeon a MIME-type and set the Content-Disposition header?:

<FilesMatch "\.(?i:ext)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>

Windows? Mac? Mixed? Might be worth looking through support.google.com/chrome/a/answer/3115278?hl=en for some pointers.

Offline

#8 2020-10-16 07:57:03

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 535

Re: Force a web browser to open or save files rather than auto download

Thank you everyone for your replies they are much appreciated.

The question was more of a browser related query but the Textpattern solution of using etc_output_file could be very useful as well since we run a variety of different systems here.

Offline

Board footer

Powered by FluxBB