Search code examples
phpcakephphttp-headershttpresponsecakephp-2.8

Cakephp 2, response body content type not working


$this->autoRender = false;
$this->response->header("HTTP/1.1 200 OK");
$this->response->header("Pragma: public");
$this->response->header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
$this->response->header("Cache-Control: private", false);

//$this->response->header("Content-type: image/png"); //tried also
$this->response->type('jpg');

$this->response->body(readfile($file));

return $this->response;

Always returns Content-Type: text/html; charset=UTF-8.

Thanks


Solution

  • $this->response->body(readfile($file));
    

    Change this line to

    $this->response->body(file_get_contents($file));
    

    And works.

    I know that it is more performant readfile, but at the moment, should work.

    Probable something that readfile breaks with the enconding.