Sunday, March 1, 2009

Re: Media View not downloading unless I set headers

Okay, after a short distraction regarding pagination, I went in and
checked both the Cake and Apache logs.

The Cake error.log shows no errors. (\app\tmp\logs)

There were also no errors in the apache\logs\error.log so I checked
out the access.log. The response was...

127.0.0.1 - - [01/Mar/2009:17:14:07 +0100] "GET /books/view/1 HTTP/
1.1" 200 13472
127.0.0.1 - - [01/Mar/2009:17:14:09 +0100] "GET /books/download/
test.epub HTTP/1.1" 200 3104

The Apache Docs say, regarding the "200", that;

"This is the status code that the server sends back to the client.
This information is very valuable, because it reveals whether the
request resulted in a successful response (codes beginning in 2), a
redirection (codes beginning in 3), an error caused by the client
(codes beginning in 4), or an error in the server (codes beginning in
5). The full list of possible status codes can be found in the HTTP
specification (RFC2616 section 10)."

Does this mean that $this->set($params); in the "Media View" is not
forcing the download? Any ideas on where I am going wrong on this?


On Feb 26, 3:04 am, brian <bally.z...@gmail.com> wrote:
> Have you checked your error log? A white screen typically means a fatal error.
>
> On Wed, Feb 25, 2009 at 5:49 PM, Mike Cook <m...@epubbooks.com> wrote:
>
> > I am unable to get the Media View to force the download to start, no
> > error is given other than it just lands on a blank page. Here's the
> > download function in my controller;
>
> >  function download ($id = null) {
> >    list($file_name, $file_ext) = split('[.]', $id);
> >    $this->view = 'Media';
> >      $params = array(
> >        'id' => $file_name . '.' . $file_ext,
> >        'name' => $file_name,
> >        'download' => true,
> >        'extension' => 'epub',
> >        'path' => 'app' . DS . 'files' . DS,
> >        'mimeType', array('epub' => 'application/epub+zip'
> >      ));
> >    $this->set($params);
> >  }
>
> > Like I say, no download (I tried with an without the 'app'.DS on the
> > path) but if I send the headers like in this post then it works;
>
> >http://groups.google.com/group/cake-php/browse_thread/thread/cf567fbb...
>
> > So, I replace $this->set($params) with;
>
> >      if(!empty($id)){
> >      $file = $params['path'] . $params['id'];
> >      $data = file_get_contents($file);
> >      $size = filesize($file);
> >      if( isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER
> > ['HTTP_USER_AGENT'], 'MSIE') ) {
> >        header('Content-Type:application/force-download');
> >      } else {
> >        header('Content-Type:application/epub+zip');
> >        header('Content-Length:' . $size);
> >        header('Content-disposition:attachment;filename="' . $params
> > ['id'] . '"');
> >        echo $data;
> >      }
> >    } else {
> >      $this->redirect();
> >      exit();
> >    }
>
> > I guess that Media View was implemented so we don't have to send the
> > headers ourselves - or am I am wrong?
>
> > Does anyone have any ideas why the default Model View method is not
> > working?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: