Stop ACTA

DownloadView - A MediaView replacement for CakePHP

Posted in CakePHP on 03.10.2008.

For those who want to use the MediaView for downloads only, this is a simple alternative with no worries about MIME type.

Ever since my first contact with MediaView, I've had issues. My biggest complaint of course is the need for the MIME type array mapping used in it. If you haven't read it already, see why MediaView is a bleeding bastard.

In essence, DownloadView is just a MediaView ripoff, I've simply removed everything unnecessary for download and modified the params. Anyway, I believe that DownloadView will make your life a bit easier downloadwise. This is how you use it:

// in your controller
$fileName = 'FileNameYouWantTheUserTo.See';
$file = new File('fullpath/to/the/file');
$this->view = 'download';

$this->set(compact('file', 'fileName')); 

...or...

// in your controller
$fakeFile = new File('FileNameYouWantTheUserTo.See');
$file = new File('fullpath/to/the/file');
$this->view = 'download';

$this->set(compact('file', 'fakeFile')); 

And..well, that pretty much does it. Just drop download.php in your ~/views folder and you're ready to go.

DownloadView is available for download here:

Comments & suggestions are always welcome ;-)

Article comments — View · Add


Page 1 of 1

Tracy Floyd :: 21.09.2009 14:41:49
Yep ran into the same issue.. my filenames (including their extensions) were all uppercase so I was getting that same blank page.. thanks for this :)
Joe :: 07.01.2010 15:08:00
Doesn't work for me !
Does it works with the last release of Cakephp ?
Media View work wih Firefox and Internet Explorer but not with Chome !

Can you help me ?
Hayden Thring :: 09.09.2011 09:20:41
works as said, very easy, thankyou :)