On Tue, Feb 22, 2011 at 8:55 AM, a17s <godlyfr...@googlemail.com> wrote:
> Hello,
> I am trying to use the MediaView class to set a download of pdf file.
> So far my attempts are not working and I can't seem to find any fault
> in my code copied from the book.cakephp.org website. Any help or
> thoughts will be appreciated.

Define "not working" please.

> Find sample code below:
>
>
> $this->view = 'Media'; //set to media download
>                $params = array(
>                        'id' => 'catalogue.pdf',
>                        'name' => 'new_catalogue',
>                        'download'=>true,
>                        'extension' => 'pdf',
>                        'path' => $this->webroot . 'files' . DS   );
>                $this->set($params);

What is $this->webroot? Is there a reason you're not using WEB_ROOT?
If you're trying to keep this configurable (perhaps it could be APP--a
more reasonable use for MediaView, anyway) it might be better to use a
more neutral variable name, like $this->_base.

In any case, as Sam mentioned, be sure to debug or log the path. Are
you seeing a 404? Are you sure it's not a 404 due to some error and
debug being set to 0? If unsure, alter the MediaView render() method
to do something besides throwing a 404 for a missing file.

Or just triple-check the path and that the file you want it really
there and accessible.

I can't remember why but my code also always includes the MIME type:

'mimeType' => array($result['ItemFile']['type'])

Note that it's an array.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to