Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-06-09 22:54:34

frickinmuck
Member
Registered: 2008-05-01
Posts: 111

How do I generate a direct file link from a file ID?

I’m working with a website that has audio files for play and download. In order to get the player to work I need a proper file link. The usage

txp:file_download_link id=“txp:custom_field name=“download-mix” (custom field just has the ID number for the file) generates the following:

http://website.com/file_download/1/example-file.mp3

When what I really need is:

http://website.com/files/example-file.mp3

Anyone able to help me out with the proper tag format to generate a direct link to the actual file? Thanks so much.

Would be really easy if txp:file_download_name had an ID attribute. Then I could just go txp:site_url/files/txp:file_download_name id=“txp:custom_field name=“download-mix” or something, but I have been racking my brain and can’t for the life of me think of a way to generate a direct link using the file ID. I don’t want to have to use a custom field to input the filename for every file in each article…

Last edited by frickinmuck (2021-06-09 23:28:03)


The AI does not hate you, nor does it love you, but you are made out of atoms which it can use for something else.

Offline

#2 2021-06-10 00:07:46

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

Re: How do I generate a direct file link from a file ID?

Untested but can you just wrap the download with a ‘list’ of one id:

<file::download_list id='<txp:custom_field name="download-mix" />'>
<a href="/files/<file::download_name />"><file::download_name /></a>
</file::download_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

Board footer

Powered by FluxBB