I'm using Typo3 with extbase and fluid. I have a Controller with an action called downloadAction()
. After calling the action the system tries to render the download-template (but I just want to start a download).
public function downloadAction($id) {
// create file
// send header
// dump file
// exit
}
How can I dump the created download-File
and send a download header instead of the normal render process? What is the best way?
Thanks
Update: This actually doesn't work with activated compression because the Content-Length will still represent the uncompressed size. eID could be used as workaround in fact there is even a official call for that:
eID = "dumpFile" see typo3/sysext/core/Resource/PHP/FileDumpEID.php
However this call won't force a download but instead "dump" it. I've made a ticket @ Forge to fix this (which was accepted and is targeted for LTS 7): https://forge.typo3.org/issues/67111
Old answer: As for now the easiest way to accomplish this is:
TypoScript Constants
TypoScript Setup
Controller Action
Fluid
The benefits vs the other mentioned answers are as following:
Side note: iPhone ignores the Content-Disposition headers (always inline)
About the "exit" concerns i've not tested it but with the page type it might work if you would use a own PHPView (StandaloneView?).
I did this in a project some months ago, it's pretty straight forward.
You can define a special PageType for download requests:
"efempty" must be replaced by your extension's name.
You are now able to trigger the download like this:
As long as headers haven't already been sent, there is nothing at all stopping you from emitting your headers, sending the content and actually calling
exit
, though you might want to check for output buffering and clear any open buffers before doing so. You might also want to inspect the list of headers that will be sent.