Question

I recently migrated my site from CakePHP 1.1 to 1.3.

I am now using media view to download files, however, I have a major problem.

When I download a zip file through media view, and try to extract it, windows claims the file is empty. If I try to preview it, it says it is invalid.

  • The file size is correct, same size as on server
  • I can download the exact same file from the server via FTP, and it is correct
  • I can download a pdf file through media view, and IT works correctly (but ZIP files do not)

Here's my controller code:

        $this->view = 'Media';
    $downloadparams = array(
          'id' => 'junkstuff'.'.zip',
          'name' => 'junk3',
          'download' => true,
          'extension' => 'zip',  // must be lower case
          'path' => APP . 'tmp/files' . DS   // don't forget terminal 'DS'
     );
   $this->set($downloadparams);

Again, if I change to a pdf file, and change 'extension' to 'pdf', it all works correctly. Debug is set to 0.
My code usage is straight from the 1.3 Cakebook: http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Views.html

Funny enough, they use zip as an example in the cakebook ....

What might I be doing wrong?

For reference, this thread appears to be the exact same issue, but it has no answers either: when opened with winrar, Zip file obtained through Cakephp MediaViews reports Unexpected end of archive

Was it helpful?

Solution 2

It turns out that when I put the site live on the live server (it was on a server, but my "test" server), this problem fixed itself. The only thing I can think of it that somewhere there was a reference or a security check that referenced the official site name. My test site had a different site address.

That's a guess. I'm really not sure what it fixed itself. But I didn't change the code, and it started working on the live site.

OTHER TIPS

Your content type might be wrong (which happens when not using the reponse class - which you cannot do in 1.3 of course):

Content-Type    application/octet-stream

Should better be

Content-Type    application/x-compressed

Also the content length might be useful. You can try to add those headers manually using header().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top