RXC
RXC

Reputation: 1233

Wrong File Type for File Download - CakePHP

In my cakephp web page, I have a button that the user clicks and it performs some maintenance on the server and then presents a download to the user. The file download is testlogs.gzip but when the download option occurs in firefox, it comes up as a file type of html document.

The file downloads and extracts fine, but I want the file type to be correct.

Here is the Media view class for the download:

        //$this->autoRender = false;
        $this->viewClass = 'Media';
        $params = array(
            'id' => 'systemlogs',
            'name' => 'testsystemlogs',
            'download' => true,
            'extension' => 'gzip',
       //   'mimeType' => 'zip',
            'path' => DS . 'home' . DS
        );
        $this->set($params);

I tried to add in the 'mimeType' => 'zip' but that did not work.

Any help would be great.

Thanks

UPDATE: I tested uploading of the same files and I used firebug to determine the content type. The only file types I care about are of type: application/octet-stream. So I think I just need to set this type in the Media class settings, not sure how to do that though. THanks

Upvotes: 0

Views: 616

Answers (1)

Mike
Mike

Reputation: 4878

mimeType has to be specified as an associative array (extension -> type), in your case this would be array('gzip' => 'application/x-gzip'). CakePHP merges this array with the built-in array of known MIME types in CakeResponse class.

However, CakePHP already knows the MIME type of .gz files so changing the extension of your file, if it is an option, might be an even easier solution.

Upvotes: 2

Related Questions