CCR
CCR

Reputation: 154

Typoscript filelink - Wrap URL within link

First, here is the Typoscript :

20 = TEXT
20 {
 value {
  field = field_title
  wrap = |.txt
  }
 filelink {
  stdWrap.wrap = <li>|</li>  
  path = fileadmin/txt-files/
  }
 } 

The result I get is :

<li>
 <a href="/fileadmin/txt-files/Title.txt">
  <img src="typo3/sysext/frontend/Resources/Public/Icons/FileIcons/txt.png">
 </a>
</li>

And what I need is :

<li>
 <a href="/fileadmin/force_download_script.php?filepath=/fileadmin/txt-files/Title.txt">
  <img src="typo3/sysext/frontend/Resources/Public/Icons/FileIcons/txt.png">
 </a>
</li>

I need to make the link downloadable, rather than opening the file in the browser. For that I have a force_download_script.php, but when I do that :

wrap = fileadmin/force_download_script.php?filepath=|txt

instead of the current wrap, filelink doesn't find the file anymore.

I have tried using ATagBeforeWrap.wrap but it doesn't look like it's made for that purpose. I also tried typolinkConfiguration.wrap without any success.

Any idea of how to achieve that ? Using a COA maybe ?

Thank you !

Upvotes: 0

Views: 732

Answers (4)

Thomas L&#246;ffler
Thomas L&#246;ffler

Reputation: 6164

To use the TYPO3 core solution with file links you can use this guide:

  1. Create a file storage where you want your "secured" files in TYPO3 backend
  2. Do not set the checkbox "Is public?" in the storage record
  3. The links will be rendered with eID and file parameters
  4. You can look into the FileDumpController handling these links: https://github.com/TYPO3/TYPO3.CMS/blob/2348992f8e3045610636666af096911436fa1c89/typo3/sysext/core/Classes/Controller/FileDumpController.php
  5. You can use the included hook to extend this controller with your logic.

Unfortunately I can't find any official documentation for this feature, but will post it when I find something or wrote it myself. ;)

Maybe this can help you, too: https://extensions.typo3.org/extension/fal_securedownload/

Here is the official part, but it's not much: https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Fal/Administration/Storages.html?highlight=filedumpcontroller

Upvotes: 0

Rudy Gnodde
Rudy Gnodde

Reputation: 4565

I would not do this with a script, but with server configuration. If you use Apache and have .htaccess enabled, you can add the configuration to a .htaccess file in the directory where the files are located. See https://css-tricks.com/snippets/htaccess/force-files-to-download-not-open-in-browser/

Alternatively you can also use the HTML5 download attribute. This is not supported by Internet Explorer however (it is supported by Edge though).

Upvotes: 1

Bernd Wilke πφ
Bernd Wilke πφ

Reputation: 10790

Are you sure .filelink is what you are looking for?

.filelink is for a set of files. For all files in the folder given by .path a link will be generated. see manual

From your description you want a text wrapped with a link to one single file. That would be more a problem for .typolink where you specify the link in .parameter.

if you really want a link list of multiple files, each wrapped with your script you need to modify .typolinkConfiguration.parameter which will be used internaly by .filelink.

Anyway it might be possible to do a wrap which then would be:

.typolinkConfiguration.parameter.wrap = /fileadmin/force_download_script.php?|

Maybe it is easier to build your list with .stdWrap.filelist, where you can use the filenames in any way to wrap your own href parameter for an A-tag.

Upvotes: 0

David
David

Reputation: 6084

The issue can get quite a bit complicated, but step by step:

  • your code above might be wrong if it's not just a copy & paste fault:
    wrap = fileadmin/force_download_script.php?filepath=|.txt
    The dot before txt was missing.
    Nevertheless it is still interesting if the php-script is triggered.
  • It's possible that the script is not triggered due to some settings in typo3conf/LocalConfiguration.php respectively some settings in the install-tool.
  • Depending on the TYPO3-Version it's also possible that the script is not triggered at all because all scripts are being required now in an extension. That means you might need to create an extension for that script.
  • Also simple wrapping of the result with the script-path might not be enough, but you have to call it explicitly by TypoScript perhaps by including the script as user-function or lib.

The admin-panel might be useful to debug some things about your script but if not you've to include some debug-output first in your own code, if that's not enough in the core (temporary).
So you've to find out if your script is triggered and if not, the reason for it.

Upvotes: 0

Related Questions