Cakephp 2,响应体内容类型不起作用

时间:2018-04-25 20:44:10

标签: php cakephp http-headers httpresponse cakephp-2.8

$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;

始终返回Content-Type:text / html;字符集= UTF-8。

由于

1 个答案:

答案 0 :(得分:0)

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

将此行更改为

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

并且有效。

我知道它是更高性能的readfile,但此刻,应该可以工作。

可能是readfile因enconding而中断的内容。