Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-12-24 03:14:16

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 2,340
Website

TXP file_download tags and the HTML download attribute

Does TXP enforce a Content-Disposition header on txp:file_download ? And if so, does it specify a filename? That would override the value specified in the download attribute1. Something like:

content-disposition:attachement; filename="filename.ext"

I am trying to use the download attribute to set the file name on some downloads and override the default, but when using any of the TXP tags, this fails: the filename as registered on the server and in the TXP DB is used. From my shortcode, simplified

<txp:file_download id='<txp:yield name="id" />'>
  <a href="<txp:file_download_link />" download="<txp:yield name="filename">download the file</a>
</txp:file_download>

The generated HTML code:

<a href="/file_download/322/test.txt" download="test download document.txt">Download Text</a>

The user should then find the “test download document.txt” file in her/his downloads folder (and the browser download manager), but “test.txt” is there.

I’ve tried many permutations of the code above, but as soon as I use one of the <txp:file_download_** /> tags, things go wrong.

1 references on MDN: developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition and developer.mozilla.org/en-US/docs/Web/HTML/Element/a


Where is that emoji for a solar powered submarine when you need it ?

Offline

#2 2020-12-24 23:29:19

etc
Developer
Registered: 2010-11-11
Posts: 4,252
Website GitHub

Re: TXP file_download tags and the HTML download attribute

Yep, headers served via file_download section are hard-coded, though one can override them with a tiny plugin. I would make it more configurable, don’t remember what are the drawbacks.

Offline

#3 2020-12-25 00:59:47

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 2,340
Website

Re: TXP file_download tags and the HTML download attribute

Ok, thanks for confirming. The issue I have is one of versioning as TXP does not change the filename.ext when you replace the existing file with a new one. And changing the file name is one of the tricks to beat some agressive caching (less a problem nowadays, but I remember having serious issues with IE 10 and older). For the user it is also nice to have some versioning indication in the filename, especially for archiving purposes.

At the moment I use the adi_file_tab plugin for that purpose, I was investigating if it was possible to go plugin-free for that.


Where is that emoji for a solar powered submarine when you need it ?

Offline

#4 2020-12-25 08:48:26

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,244
Website GitHub

Re: TXP file_download tags and the HTML download attribute

phiw13 wrote #327800:

At the moment I use the adi_file_tab plugin for that purpose, I was investigating if it was possible to go plugin-free for that.

One day. Bringing the coolest bits of adi_file_tab into core is on the list.


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-12-25 09:10:40

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 2,340
Website

Re: TXP file_download tags and the HTML download attribute

Bloke wrote #327848:

One day. Bringing the coolest bits of adi_file_tab into core is on the list.

Now that would be nice!


Where is that emoji for a solar powered submarine when you need it ?

Offline

Board footer

Powered by FluxBB