0

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 !

CCR
  • 154
  • 4
  • 18
  • Which TYPO3 version are you using? I wouldn't recommend you to use some scripts for download that go beside TYPO3. Use the core and its possibilities! – Thomas Löffler Jul 14 '18 at 17:11
  • I am using **Typo3 7.6**. I'd surely love not to need a script but I haven't find a way to do that with Typoscript. Yet =) – CCR Jul 16 '18 at 12:12

4 Answers4

1

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).

Rudy Gnodde
  • 4,286
  • 2
  • 12
  • 34
0

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.

David
  • 5,882
  • 3
  • 33
  • 44
0

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.

Bernd Wilke πφ
  • 10,390
  • 1
  • 19
  • 38
  • I'm using `filelink` rather than `typolink` because it allows me to "check" if the file I'm linking to exists (see [Old post](https://stackoverflow.com/questions/51176829/typoscript-link-a-file-only-if-it-exists-using-url)). `typolinkConfiguration.parameter` doesn't seem to be possible: [TsRef](https://docs.typo3.org/typo3cms/TyposcriptReference/7.6/Functions/Filelink/#typolinkconfiguration) but maybe I'm wrong… `.stdWrap.filelist` is a good idea, but difficult to implement given how my fileadmin is made. – CCR Jul 16 '18 at 13:58
  • with `.filelist` you only get existing files, it is a folder listing. if your editor should select files never do it in a text-/string-field where he enters a name. Always use relations to sys_file, so the file is referenced and can't be deleted (in the TYPO3 BE) – Bernd Wilke πφ Jul 17 '18 at 06:00
0

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

Thomas Löffler
  • 5,922
  • 1
  • 14
  • 29