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: 118

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: 11,271
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

#3 2022-03-09 07:29:00

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 446
Website

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

Bloke wrote #330416:

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

<file::download_list id='<txp:custom_field name="download-mix" />'>...

Thanks, Bloke. I used this to create a shortcode for outputting a simple audio player. The mp3 file is uploaded to files. Just add the file id to the shortcode.

Form

Name: media_audio

<p class="text-center mt-4"><file::download_list id='<txp:yield name="id" />'>
<audio controls="controls">
  <source src="/files/<file::download_name />" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</file::download_list></p>

If the file title is needed, add this after </audio>:

<br /><file::download_name title="1" />

Shortform

<txp::media_audio id=""/>

You can see it in action in this article about rice cultivation in Japan at 10. Husking.


Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
JapaneseStreets.com – Japanese street fashion (mostly txp)

Offline

Board footer

Powered by FluxBB