Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2020-10-15 11:06:47
- Algaris
- Member
- From: England
- Registered: 2006-01-27
- Posts: 557
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
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
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
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
Re: Force a web browser to open or save files rather than auto download
If this can help: etc_output_file.
Offline
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
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: 557
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