Cakephp 2,响应正文内容类型不起作用
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;
总是returns内容类型:text/html;字符集=UTF-8.
谢谢
$this->response->body(readfile($file));
将此行更改为
$this->response->body(file_get_contents($file));
并且有效。
我知道它是性能更高的 readfile,但目前应该可以。
可能是 readfile 的某些内容与 enconding 中断了。
$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;
总是returns内容类型:text/html;字符集=UTF-8.
谢谢
$this->response->body(readfile($file));
将此行更改为
$this->response->body(file_get_contents($file));
并且有效。
我知道它是性能更高的 readfile,但目前应该可以。
可能是 readfile 的某些内容与 enconding 中断了。