RSS 2.0
RSS 0.91
ATOM 0.3
July 24, 2011

Create a download action with Extbase

Category: Søren Malling

Do you want to make some statistic etc. before letting a user download a file. You can use a standard Extbase action to fullfill your needs :)

Single view in FDFs Mediadatabase

Single view in FDFs Mediadatabase

Lately I've been working on a mediadatabase for the danish scout-like organization Frivilligt Drenge- Og Pige-Forbund, FDF

As a natural part of a mediadatabase, a visitor should be able to download the media file. But, we would also like to make some statistic on each download. So, instead of creating links directly to the original media file, I created a downloadAction inside my mediaController.

But, normally actions shows the corresponding HTML template.. So I've had to "manipulate" the response object Extbase gives me

public function downloadAction(Tx_Mediadatabase_Domain_Model_Media $media) {
// Do something "fun" here.. Statistic, counting, notify, etc.
$this->response->setHeader('Cache-control', 'public', TRUE);
$this->response->setHeader('Content-Description', 'File transfer', TRUE);
$this->response->setHeader('Content-Disposition', 'attachment; filename=FILENAME.jpg', TRUE);
// ATTENTION: I've hardcoded the Content-Type, you might have to change this!
$this->response->setHeader('Content-Type', 'image/jpeg', TRUE);
$this->response->setHeader('Content-Transfer-Encoding', 'binary', TRUE);
// As the very last thing, I send the headers to the visitor, before Extbase comes to the part, where it renders a HTML template
// $this->media is my domain model, add you own file path here :-) 

Another fun part in this project, was using the FLUIDTEMPLATE as template engine. As the mediadatabase was the only content in this pagetree (no text, text with image etc. element) I was able to take full advantage of Fluid with Layouts and Partials beside the normal templates for each actions.


comment #1
Gravatar: Soren Malling Soren Malling July 28, 2011 15:15
In my search for other Extbase stuff I found this forum/question and this pretty cool solution[..] support for several filetypes.

I hope this might help others! :)

comment #2
Gravatar: Alexandra Alexandra August 2, 2011 11:32
Great site!! Go on for this. Greetings from Germany! :)

comment #3
Gravatar: Marco Marco August 4, 2011 21:17
I thought there was a plugin for typo3 which that you can create a download or not?

comment #4
Gravatar: Soren Malling Soren Malling August 8, 2011 13:09
There is the filelist content element.

But as this was made as a part of a Extbase extension, I needed to present the download in a different way than a direct link to the original resource.

Sorry, comments are closed for this post.