1
$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。

谢谢

4

1 回答 1

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

将此行更改为

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

并且有效。

我知道它是性能更高的读取文件,但目前应该可以工作。

readfile 可能会因编码而中断。

于 2018-04-26T14:23:12.810 回答